Partager via


Introduction to MSHTML Editing

The editor provided with MSHTML offers a "what you see is what you get" (WYSIWYG) HTML editing environment with a rich set of capabilities. It can be activated from C++, Visual Basic, and script. You can use a number of techniques to customize the MSHTML Editor. These techniques are available in C++ only.

  • Overview
  • Activating the MSHTML Editor
  • Modifying Documents in Edit Mode
  • Activating Additional Editing Features
  • Using Custom Images to Represent Tags
  • Controlling Element Resizing and Positioning with IHTMLEditHost
  • Customizing Event Handling with Edit Designers
  • Manipulating the Markup in a Document
  • Other Features You Can Use with the MSHTML Editor
  • The DHTML Editing Component

Overview

In addition to its HTML rendering and parsing capabilities, MSHTML exposes a WYSIWYG HTML editing functionality. Applications hosting MSHTML can exploit these editing features to enable editing of HTML content in a manner similar to text editing in word processors.

Applications that use HTML to render information or content can use MSHTML editing functionality to enable end users to alter that information. For example, an e-mail application that renders e-mail messages with HTML could use the MSHTML editing features to enable end users to alter messages in the content area. Instead of spending time developing editing features for message rendering, developers can use the MSHTML implementation of these capabilities. This frees up their time to concentrate on improving their e-mail communication functionality.

Applying WYSIWYG editing to HTML authoring not only improves an author's control of format and appearance, but can also help authors work effectively without knowing HTML. By hosting MSHTML in an application, developers can provide users with a simple WYSIWYG Web authoring tool. Users can simply click buttons to alter paragraph formats, font sizes, typefaces, font weights, colors, and so on.

MSHTML Editing provides the following functionality to the user:

  • Standard editing functionality such as caret positioning, keyboard navigation, drag-and-drop, and content selection.
  • Copy, cut, delete, and paste operations.
  • Multi-level undo and redo.
  • The ability to toggle selected text between bold, italic, and/or underlined.
  • The ability to alter typeface, font size, forecolor (text), and backcolor (background).
  • The ability to remove formatting.
  • The ability to increase or decrease indentation.
  • The ability to justify text (left, center, right).
  • The ability to create ordered and unordered lists.
  • The ability to create a hyperlink or bookmark.
  • The ability to insert a horizontal line.
  • The ability to insert an image.
  • The ability to insert a variety of intrinsic controls. These include buttons, text boxes, radio buttons, check boxes, submit controls, and drop-down and list boxes.

Hosting applications can exploit the MSHTML Editor as a means to generate proper and consistent HTML and XML code. The MSHTML Editor generates standard HTML, allowing third-party applications to quickly adapt the latest Microsoft browser features.

Activating the MSHTML Editor

Microsoft Visual Basic, C++, and script all offer ways to activate the MSHTML Editor. This means you can use the Editor in an application hosting MSHTML or the WebBrowser, or on a Web Page displayed by Windows Internet Explorer. The Editor can be activated on a whole document or on individual elements within a document.

To learn how to activate the MSHTML Editor, see Activating the MSHTML Editor.

Modifying Documents in Edit Mode

The MSHTML Editor provides you with commands with which to alter the current selection. These commands are available in C++, Visual Basic, and script. They are executed by the IOleCommandTarget::Exec or IHTMLControlRange::execCommand method. The commands you can perform include bolding, italicizing, aligning, changing colors and fonts, and inserting new elements.

For more information, see Modifying Documents in Edit Mode and MSHTML Command Identifiers.

Activating Additional Editing Features

The MSHTML Editor has a set of extra features that are turned on and off using command identifiers issued through IOleCommandTarget::Exec method. These features are available in C++; they include multiple selection, two dimensional positioning, live resize, and automatic detection and linking of URLs.

For more information, see Using the MSHTML Editor's Extra Features.

Using Custom Images to Represent Tags

There are a number of additional commands which turn on and turn off glyphs to represent the tags in a document. These glyphs need to be provided by the host in the form of .gif or .bmp images. Glyphs provide simple, iconic guidance to someone using the Editor so they can see the underlying markup that formats a document.

For more information, see Using Editing Glyphs and MSHTML Command Identifiers.

Controlling Element Resizing and Positioning with IHTMLEditHost

Implementing IHTMLEditHost allows you to control the final size and position of an element when the user resizes or moves it in the MSHTML Editor. You could implement a snap-to-grid feature with IHTMLEditHost, for instance. It is only available from an application hosting MSHTML.

For more information, see Implementing IHTMLEditHost.

Customizing Event Handling with Edit Designers

By implementing the IHTMLEditDesigner interface, you can intercept events occurring in the MSHTML editing environment and provide your own custom processing for them. This custom processing can accompany or replace the default processing provided by the MSHTML Editor. You can attach more than one edit designer to the MSHTML Editor at the same time. Edit designers can be used in applications hosting MSHTML or in binary behaviors.

For more information, see About Edit Designers, Implementing Edit Designers: The Basics, and Implementing Edit Designers 2: The Annotator Sample.

Manipulating the Markup in a Document

For closer control of the editing process, the MSHTML Editor provides a set of service interfaces that let you directly navigate and manipulate the markup, selection, insertion point, and highlighting in a document. These services offer editing control that includes information about how a document is rendered on the screen, including the location of the insertion.

For more information, see Introduction to Markup Services, IHTMLCaret, IDisplayPointer, IMarkupContainer2, IMarkupPointer2, IMarkupServices2, ISelectionServices, and IHighlightRenderingServices.

Other Features You Can Use with the MSHTML Editor

When customizing the MSHTML Editor, you might find these additional components useful.

  • Rendering behaviors provide customized drawing in the browser or on a Web page. They might be useful, for instance, in creating guidelines for positioning elements on a page. See Using Rendering Behaviors to learn how to use rendering behaviors, and Implementing IHTMLEditHost for an example of their use with the MSHTML Editor.
  • Change Logs enable you to track the changes taking place in a document that's being edited and restore or reapply them as necessary.
  • MarkupTextFrags enable you to attach comments or other text to a document that is not actually part of the document object model. When the document is saved, these markup text fragments are saved as conditional comments.

The DHTML Editing Component

The DHTML Editing Component and ActiveX control are still available. They provide similar features to the MSHTML Editor, though they are not customizable. The DHTML Editing Component includes the following features:

  • Table operations (insert row, insert column, merge cells, and so on).
  • Absolute drop mode.
  • Source code white space and formatting preservation.
  • Active Server Page script preservation.

The DHTML Editing Component ActiveX control provides the functionality of the DHTML Editing Component implemented in an easy-to-use control. The control also adds:

  • Loading and saving files.
  • Context menu support.
  • Keyboard accelerators.
  • Properties, methods, and events that expose editing functionality.