Export (0) Print
Expand All
2 out of 7 rated this helpful - Rate this topic

IDocHostShowUI::ShowMessage Method

Called by MSHTML to display a message box.

Syntax


HRESULT ShowMessage(
    HWND hwnd,
    LPOLESTR lpstrText,
    LPOLESTR lpstrCaption,
    DWORD dwType,
    LPOLESTR lpstrHelpFile,
    DWORD dwHelpContext,
    LRESULT *plResult
);

Parameters

hwnd
[in] The HWND of the owner window.
lpstrText
[in] A LPOLESTR pointer to a string containing the text for the message box.
lpstrCaption
[in] A LPOLESTR pointer to a string containing the caption for the message box.
dwType
[in] A DWORD containing the flag type (taken from the MessageBox MB_xxxx constants).
lpstrHelpFile
[in] A LPOLESTR pointer to a string containing the Help file name.
dwHelpContext
[in] A DWORD containing the Help context identifier.
plResult
[out] A pointer to an LRESULT that indicates what button the user clicked (taken from the MessageBox IDxxx constants).

Return Value

Returns one of the following values.

S_OK Host displayed its UI. MSHTML does not display its message box.
S_FALSE Host did not display its UI. MSHTML displays its message box.

Example

When your application hosts the browser control, you can replace the Windows Internet Explorer message box caption (which is used for Microsoft JScript alerts among other things) with a custom caption. The Internet Explorer message box caption is stored as a string resource in Shdoclc.dll. It is identified by the symbol IDS_MESSAGE_BOX_TITLE, which has a value of 2213. You can load this resource and compare it with the lpstrCaption value to determine when to replace the message box caption with a custom string. The following example shows one way you can implement IDocHostShowUI::ShowMessage.

security note Security Alert  If you load the wrong DLL by using LoadLibrary, you can compromise the security of your application. See the LoadLibrary documentation for information on how to correctly load DLLs with different versions of Windows.

HRESULT CBrowserHost::ShowMessage(HWND hwnd,
                                  LPOLESTR lpstrText,
                                  LPOLESTR lpstrCaption,
                                  DWORD dwType,
                                  LPOLESTR lpstrHelpFile,
                                  DWORD dwHelpContext,
                                  LRESULT *plResult) 
{
    USES_CONVERSION;
    TCHAR pBuffer[50];

    // resource identifier for window caption "Microsoft Internet Explorer"
    #define IDS_MESSAGE_BOX_TITLE		   2213

    // Load Shdoclc.dll and the IE message box title string
    HINSTANCE hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL"));
	
    if (hinstSHDOCLC == NULL)
    {
       //Error loading module -- fail as securely as possible
       return;
    }
 
    LoadString(hinstSHDOCLC, IDS_MESSAGE_BOX_TITLE, pBuffer, 50);

    // Compare the IE message box title string with lpstrCaption
    // If they're the same, substitute your own Caption
    if (_tcscmp(OLE2T(lpstrCaption), pBuffer) == 0)
        lpstrCaption = L"New Caption";

    // Create your own message box and display it
    *plResult = MessageBox(OLE2T(lpstrText), OLE2T(lpstrCaption), dwType);

    // Unload Shdoclc.dll and return
    FreeLibrary(hinstSHDOCLC);
    return S_OK;
}

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.