Internet Explorer 5.5 Demos : Edit Designer Monitor (IE 5.5)

Description: An edit designer is a COM component that allows you to customize the MSHTML Editor. The only interface an edit designer must implement is IHTMLEditDesigner, which has four methods that act as callback routines. The MSHTML Editor calls these methods in response to events occurring in the Editor.
These methods are:
IHTMLEditDesigner::PreHandleEvent
IHTMLEditDesigner::PostHandleEvent
IHTMLEditDesigner::TranslateAccelerator
IHTMLEditDesigner::PostEditorEventNotify

More Details
The sample for this tutorial implements an IHTMLEditDesigner interface that monitors the calls to the IHTMLEditDesigner methods. It demonstrates the important features of edit designer implementation:
How to implement IHTMLEditDesigner.
How to use IHTMLEditServices::AddDesigner to attach an edit designer to the MSHTML Editor.
How to use IHTMLEditServices::RemoveDesigner to detach an edit designer from the MSHTML Editor.
How the return values from the edit designer methods control event processing in the MSHTML Editor.
The sample is a simple browser implementation with an address bar, five buttons, and a combo box. It monitors calls to the edit designer methods so that you can see the pattern of interaction between an edit designer and the MSHTML Editor. The specifications are as follows:
The Design Mode button switches the browser between design mode and browse mode.
The PreHandle S_OK button, when depressed, causes the edit designer to return S_OK from its PreHandleEvent call. When the button is not depressed, the edit designer returns S_FALSE.
The PostHandle S_OK button, when depressed, causes the edit designer to return S_OK from its PostHandleEvent call. When the button is not depressed, the edit designer returns S_FALSE.
The TransAcc S_OK button, when depressed, causes the edit designer to return S_OK from its TranslateAcceleratior call. When the button is not depressed, the edit designer returns S_FALSE.
The list box on the left side records the edit designer methods as they are called, along with an event description. You can double click on any item in the list for more detailed information on the event.
The check boxes below the list box allow you to prevent some event messages from being recorded in the list box. Note that the check boxes only prevent the list box from recording these events; the events occur in the edit designer regardless of any selection made in the check boxes.
Structurally, the sample consists of three classes, implementing three interfaces. The classes are:
CEdMonitor: this class implements IHTMLEditDesigner along with a supporting interface, IEDMessenger, and is the focus of this article. CBrowserHost: this class implements the application's window-which includes a WebBrowser control, buttons, and text boxes-and implements IBrowserHost to create, show, hide, and destroy the window. The function of most interest here is CBrowserHost::OnButton1. OnButton1 switches a document displayed in the WebBrowser control between design and browse mode. In the course of switching modes, the application instantiates or releases the Edit Designer Monitor's IHTMLEditDesigner interface and adds or removes it from the MSHTML Editor.
CExeModule: this class is the server for the executable file. This module exposes the CBrowserHost and CEdMonitor objects. For the purposes of this article, this class only provides support and won't be discussed further.
The sample has been kept simple in order to focus on the implementation structure of edit designers. For this reason, the sample performs minimal error checking and no exception handling. A "real-world" application generally provides more robust error checking and exception handling.

Browser/Platform Compatibility
This sample requires Microsoft Internet Explorer 5.5 or later installed on Microsoft Win32. Header files and libraries for Win32 and Internet Explorer 5.5 or later are also necessary for use in your development environment.

Usage
Note You must download the sample to your own computer to run it. The source code for this sample is included in a Microsoft Visual C++ 6 workspace. It uses ATL to provide COM support, standard implementations of some of the standard interfaces, and "smart" interface pointers that handle their own reference counting. You can use this sample as a structure for building your own implementations of IHTMLEditDesigner.

In principle, implementing IHTMLEditDesigner is quite simple. You need to implement just one interface, IHTMLEditDesigner. No other supporting interfaces or components are required, though in most cases they will be desirable or necessary. A stripped-down class declaration for an edit designer, in which IHTMLEditDesigner is implemented by inheritance, might look like this:

class CMyDesignerImpl :
public IHTMLEditDesigner,
public ISupportingInterface
{
public:
// IHTMLEditDesigner
HRESULT PostEditorEventNotify(DISPID inEvtDispId, IHTMLEventObj *pIEventObj);
HRESULT PostHandleEvent(DISPID inEvtDispId, IHTMLEventObj *pIEventObj);
HRESULT PreHandleEvent(DISPID inEvtDispId, IHTMLEventObj *pIEventObj);
HRESULT TranslateAccelerator(DISPID inEvtDispId, IHTMLEventObj *pIEventObj);

// ISupportingInterface
HRESULT SetHost(IUnknown* pUnkHost);
HRESULT SetDoc(IHTMLDocument2* pDoc);

// IUnknown
ULONG AddRef();
HRESULT QueryInterface(REFIID iid, void** ppv);
ULONG Release();
};

Once implemented, IHTMLEditServices::AddDesigner and IHTMLEditServices::RemoveDesigner enable you to activate and deactivate a designer at will.
Note for more documentation on implementing this sample see Implementing Edit Designers: The Basics in the MSDN Online Web Workshop.

Remember you will need to include the Internet Explorer 5.5 header library files, and the Windows 2000 Headers and Libraries from the Platform SDK, in your development path when building the sample source code.

Complete Article

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish