HTML Dialog Boxes

HTML Dialog Boxes


IE4/MSHTML allows you to create a modal dialog box that displays HTML. This is accomplished using the ShowHTMLDialog function that is implemented in Mshtml.dll.

arrowy.gifUsing ShowHTMLDialog

arrowy.gifCreating an HTML Resource

Using ShowHTMLDialog

To use ShowHTMLDialog, it is necessary to dynamically load and then call this function by using the LoadLibrary and GetProcAddress functions. The SHOWHTMLDIALOGFN type is defined in Mshtmhst.h to define the proper function type for ShowHTMLDialog. The HTMLDlg sample in the Internet Client SDK shows a complete example using ShowHTMLDialog, including how to pass data to and receive data from the dialog. The following example shows how to obtain the address of the ShowHTMLDialog function:

#include <windows.h>
#include <mshtmhst.h>

{
HINSTANCE   hinstMSHTML = LoadLibrary(TEXT("MSHTML.DLL"));

if(hinstMSHTML)
   {
   SHOWHTMLDIALOGFN  *pfnShowHTMLDialog;
      
   pfnShowHTMLDialog = (SHOWHTMLDIALOGFN*)GetProcAddress(hinstMSHTML, TEXT("ShowHTMLDialog"));

   if(pfnShowHTMLDialog)
      {
      /*
      Perform initialization and then call ShowHTMLDialog.
      */
      }
   
   FreeLibrary(hinstMSHTML);
   }
}

The HTML for the dialog box is loaded from an IMoniker interface that is passed in the pmk parameter in ShowHTMLDialog. This moniker can be any moniker that evaluates to any HTML source or to a resource that uses the res: protocol. The CreateURLMoniker function can be used to create the IMoniker interface that is passed to ShowHTMLDialog.

The input parameters for the dialog box are passed in the pvaArgIn parameter in ShowHTMLDialog. The input parameters can be any information that can be passed in a VARIANT structure. In the dialog box HTML source, the input parameters are obtained from the dialogArguments property of the window object.

The output parameters for the dialog box are returned in the pvaArgOut parameter in ShowHTMLDialog. This is a VARIANT structure that you allocate. This structure must be initialized using the VariantInit function before calling ShowHTMLDialog. In the dialog box HTML source, the output parameters are set using the returnValue property of the window object.

SHOWHTMLDIALOGFN

typedef HRESULT STDAPICALLTYPE SHOWHTMLDIALOGFN(
    HWND hwndParent, 
    IMoniker *pmk, 
    VARIANT *pvarArgIn, 
    TCHAR* pchOptions, 
    VARIANT *pvarArgOut
);

Defines the function type for ShowHTMLDialog. This function creates a modal dialog box that contains HTML. The function does not return until the dialog box has been dismissed. The address of this function must be obtained by loading Mshtml.dll with LoadLibrary and then getting the address of ShowHTMLDialog with GetProcAddress.

hwndParent
Handle to the window that will be the owner of the dialog box. This window will be disabled for the life of the dialog box. If this value is NULL, the dialog box is not owned.
pmk
Address of an IMoniker interface that identifies the source of the HTML that will be contained in the dialog box.
pvarArgIn
Address of a VARIANT that contains the input data for the dialog box. The data passed in this VARIANT is placed in the window object's dialogArguments property. This parameter can be NULL.
pchOptions
Specifies the window ornaments for the dialog box. This parameter can be NULL or the address of a string that contains a combination of values, each separated by a ';'. See the description of the features parameter of the showModalDialog method of the window object for detailed information.
pvarArgOut
Address of a VARIANT that contains the output data for the dialog box. This VARIANT receives the data that was placed in the window object's returnValue property. This parameter can be NULL.

Creating an HTML Resource

Rather than distribute separate HTML files for your application's use, you can add the raw HTML to your application as a resource. You can then retrieve the HTML from your application when it is needed. ShowHTMLDialog is one example of how HTML can be used from a resource by using the res: protocol.

To add the HTML as a resource, you include a file that contains nothing but the actual HTML in your application's resource script. This file is included as an HTML type resource. The following example shows how to include a file called MyHTML.htm as an HTML resource.

HTML_RESOURCE HTML "MyHTML.htm"

In this example, "HTML_RESOURCE" is the identifier of the resource. This can be either a string or a numerical identifier. "HTML" is the resource type. Visual C++ 5.0 will interpret this as the numeric value 23 and will substitute 23 for "HTML" when the resource file is opened for editing. "MyHTML.htm" is the file that contains the HTML source that will be added. The resource compiler adds this file as is and will not attempt to interpret the contents of the file.

You can specify the HTML resource in any function that will accept a res: protocol. ShowHTMLDialog is one example of how HTML can be used from a resource by using the res: protocol. You can also use FindResource and LoadResource to obtain the HTML resource. In FindResource, specify the RT_HTML value for lpType to find an HTML resource.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.