Creatingan HTML Viewer Control

Before you can create an HTML Viewer control, you must 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 DLLby calling the LoadLibrary function.

    Specify 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.

    Specify DISPLAYNAME in the lpClassName parameter.

Note When you call 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").

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 Viewer Control instance
HINSTANCE hInstance;             // Application instance
HWND m_hwndHtml;                 // Handle to a 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: 
    {
      DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | 
                      WS_CLIPSIBLINGS;

      m_hwndHtml = CreateWindow (DISPLAYCLASS, 
                                 NULL,
                                 dwStyle,
                                 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;
    }
    .
    .
    .
  }
}