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