次の方法で共有


ShowMessage method

Called by MSHTML to display a message box.

Syntax

HRESULT retVal = object.ShowMessage(hwnd, lpstrText, lpstrCaption, dwType, lpstrHelpFile, dwHelpContext, plResult);

Parameters

  • hwnd [in]
    Type: HWND

    The HWND of the owner window.

  • lpstrText [in]
    Type: LPOLESTR

    A LPOLESTR pointer to a string containing the text for the message box.

  • lpstrCaption [in]
    Type: LPOLESTR

    A LPOLESTR pointer to a string containing the caption for the message box.

  • dwType [in]
    Type: DWORD

    A DWORD containing the flag type (taken from the MessageBox MB_xxxx constants).

  • lpstrHelpFile [in]
    Type: LPOLESTR

    A LPOLESTR pointer to a string containing the Help file name.

  • dwHelpContext [in]
    Type: DWORD

    A DWORD containing the Help context identifier.

  • plResult [out]
    Type: LRESULT

    A pointer to an LRESULT that indicates what button the user clicked (taken from the MessageBox IDxxx constants).

Examples

When your application hosts the browser control, you can replace the Internet Explorer message box caption (which is used for 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 Warning: 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;
}