Internet Explorer 5.5 Demos : Editing Features (IE 5.5)

Description: You can activate a number of optional features to enhance the MSHTML Editor's default behavior. For a list of these features, see the section entitled Document Level Editing Commands at the end of Using the MSHTML Editor's Extra Features in Web Workshop. The commands used to modify the Editor's behavior can be used from C++. Most of these commands work only when the browser is in design mode. They are turned off when the Editor is deactivated or the WebBrowser navigates to a new page.

More Details
The sample for this tutorial provides a demonstration of the editing features controlled through IOleCommandTarget::Exec . The sample shows:
How each of the features behaves.
How to use IOleCommandTarget::Exec to turn editing features on and off.
The specifications of this sample are as follows:

The sample is a simple browser implementation with an address bar and ten buttons.
The first button turns the MSHTML Editor on and off.
Each of the other buttons executes one of the editing feature commands, turning it on or off.
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.

Many of the interface pointers in the sample are wrapped by the CComQIPtr class. CComQIPtr is a "smart" pointer class. Besides automatic reference counting, it provides overloaded operators to make working with COM easier. CComQIPtr includes an overloaded assignment operator (operator=) which performs an automatic QueryInterface during assignment. For instance, the sample's QueryInterface call to initialize its IOleCommandTarget pointer looks like this:

// m_spWebBrowser is an already-initialized pointer to an IWebBrowser2 interface.
// m_spOleCmdTarg is a declared but uninitialized CComQIPtr for an IOleCommandTarget interface.

m_spOleCmdTarg = m_spWebBrowser;

Browser/Platform Compatibility
The Editing Features sample requires Microsoft Internet Explorer 5.5 or later on the Win32 platform. For developers, header and library files for Internet Explorer 5.5 or later are needed for use in your development environment; in particular, Mshtml.h and Mshtmcid.h are necessary.

Usage
The editing commands can be executed using the IOleCommandTarget::Exec method with command identifiers taken from the CGID_MSHTML command group. These commands are defined in Mshtmcid.h. You can obtain an IOleCommandTarget interface by calling QueryInterface on either the IWebBrowser2 or IHTMLDocument2 interface.
// Assume pWebBrowser is a valid pointer to the IWebBrowser2 interface IOleCommandTarget* pCmdTarg; pWebBrowser->QueryInterface(IID_IOleCommandTarget, (void**)andpCmdTarg);

Here is how you can turn on 2-D positioning using IOleCommandTarget::Exec:

// Declare a VARIANT data type and initialize it VARIANT var;
V_VT(andvar) = VT_BOOL; // Set the type to BOOL
V_BOOL(andvar) = VARIANT_TRUE;

// Turn on 2-D positioning for absolutely positioned elements
hr = pCmdTarg->Exec(andCGID_MSHTML, IDM_2D_POSITION, MSOCMDEXECOPT_DODEFAULT, andvar, NULL);
V_VT(X) and V_BOOL(X) are macros defined in Oleauto.h. They take a VARIANT pointer for their argument. The sample file BrowserHost.cpp includes Oleauto.h indirectly by way of Mshtmhst.h. Mshtmhst.h includes Ole2.h, which includes Oleauto.h. These macros assign a value to the appropriate member of a VARIANT structure. For instance, V_BOOL(andvar) = VARIANT_TRUE is equivalent to var.bVal = VARIANT_TRUE.

Note:Include the Windows 2000 Headers and Libraries from the Platform SDK in your development path when building this sample.

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