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.


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


[in] The HWND of the owner window.
[in] A LPOLESTR pointer to a string containing the text for the message box.
[in] A LPOLESTR pointer to a string containing the caption for the message box.
[in] A DWORD containing the flag type (taken from the MessageBox MB_xxxx constants).
[in] A LPOLESTR pointer to a string containing the Help file name.
[in] A DWORD containing the Help context identifier.
[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.


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) 
    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
    if (hinstSHDOCLC == NULL)
       //Error loading module -- fail as securely as possible
    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
    return S_OK;

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

Community Additions

© 2014 Microsoft. All rights reserved.