HTML Viewer Control

The Hypertext Markup Language (HTML) viewer control provides a viewer for displaying HTML text and embedded images. The HTML viewer provides the functionality required to implement Microsoft® Pocket Internet Explorer and the Help engine.

You can also create other viewers based on the HTML viewer control. An HTML source can include references to other sources, which may provide different types of data. If the application determines that some of the data it retrieves is of a type other than HTML, it can invoke another type of viewer to display that data.

To use the HTML viewer control, you must include the Htmlctrl.h header file and either link your application with the Htmlview.dll dynamic link, or load the HTML viewer DLL by calling the LoadLibrary function. When you call LoadLibrary, pass "Htmlview.dll" as the lpLibFileName parameter.

Before you can create or use the HTML viewer control, you have to register it by calling the InitHTMLControl function.You create an HTML viewer control by specifying DISPLAYNAME in the lpClassName parameter to the CreateWindow function.

    To create the HTML viewer control
  1. Load the HTML viewer DLL by calling the LoadLibrary function, specifying "Htmlview.dll" in the lpLibFileName parameter.
  2. Register the HTML viewer control class by calling the InitHTMLControl function.
  3. Create a window for the HTML viewer control by calling the CreateWindow function, specifying DISPLAYNAME in the lpClassName parameter.
    To display an HTML document
  1. Clear the current contents of the HTML viewer control by sending it a WM_SETTEXT message.
  2. Load an HTML document and copy the document's text to the control by sending the control a series of DTM_ADDTEXT messages for ASCII or DTM_ADDTEXTW messages for Unicode.
  3. When the document processing is complete, send the control a DTM_ENDOFSOURCE message.
  4. Process any NM_HOTSPOT notifications sent by the control when the user taps a link or submits a form.
  5. For each NM_INLINE_IMAGE notification received from the control, load the image so that the HTML viewer control will display the image loading icon.
  6. After the image has loaded successfully, send the control a DTM_SETIMAGE message containing the bitmap handle (HBITMAP) of the image to display.

    If the image does not load successfully, send a DTM_IMAGEFAIL message, which indicates to the control that it should display the broken image icon.

  7. For each NM_INLINE_SOUND notification received from the control, load the sound, and then play it the number of times indicated in the dwLoopCount parameter.

The following code example shows how to create an HTML viewer control.

#define DISPLAYCLASS  TEXT("DISPLAYCLASS")

BOOL g_bMakeFit = TRUE;          // DTM_ENABLESHRINK Shrink-enable flag
TCHAR const c_szHTMLControlLibrary[] = TEXT("htmlview.dll");

HINSTANCE g_hInstHTMLCtrl;       // HTML Control Viewer instance
HINSTANCE hInstance;             // Application instance
HWND m_hwndHtml;                 // Handle to HTML DISPLAYCLASS window

g_hInstHTMLCtrl = LoadLibrary(c_szHTMLControlLibrary);

InitHTMLControl(hInstance);

LRESULT WndProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) 
{
   switch (message) 
   {
      case WM_CREATE: 
      {
         m_hwndHtml = CreateWindow(DISPLAYCLASS, NULL,
            WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_CLIPSIBLINGS,
            rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
                hWnd, (HMENU)IDC_HTMLVIEW, g_hInst, NULL);
         SetFocus(m_hwndHtml);
         PostMessage(m_hwndHtml, DTM_ENABLESHRINK, 0, g_bMakeFit);
         break;
      }
      .
      .
      .
   }
}

Note When calling the LoadLibrary and CreateWindow functions, the library or class name has to be a Unicode string. Use the TEXT macro to cast a string as Unicode, for example, TEXT("Htmlview.dll").

Pocket Internet Explorer is an example of an application that uses the HTML viewer control. The application (Webview.exe) links with the dynamic-link library that provides the HTML viewer control (Htmlview.dll). The application provides the user interface, retrieves the data from the Uniform Resource Locators (URL), and interprets the data.

The following illustration describes how the application interacts with the HTML viewer control.

Interaction between the application and HTML viewer control

Note The HTML viewer control interface is not an ActiveX control, and does not expose any COM interfaces.