Navigation:  Internet Development > Advanced Hosting Reference > Interfaces > IDocHostShowUI >

ShowMessage

Previous pageReturn to chapter overviewNext page

描述

 

当MSHTML需要显示消息框时调用。

 

C++ 语法

 

HRESULT ShowMessage(

  HWND hwnd,

  LPOLESTR lpstrText,

  LPOLESTR lpstrCaption,

  DWORD dwType,

  LPOLESTR lpstrHelpFile,

  DWORD dwHelpContext,

  LRESULT *plResult

);

 

PowerBASIC 语法

 

METHOD ShowMessage ( _

  BYVAL hwnd AS DWORD _

  BYREF lpstrText AS WSTRINGZ, _

  BYREF lpstrCaption AS WSTRINGZ, _

  BYVAL dwType AS DWORD, _

  BYREF lpstrHelpFile AS WSTRINGZ, _

  BYVAL dwHelpContext AS DWORD, _

  BYREF plResult AS LONG _

) AS LONG

 

参数

 

hwnd

[in]HWND的所有者窗口。

lpstrText

[in]LPOLESTR指向包含消息框文本的字符串的指针。

lpstrCaption

[in]LPOLESTR指向包含消息框标题的字符串的指针。

dwType

[in]DWORD包含标志类型(取自MessageBox MB_xxxx常量)。

lpstrHelpFile

[in]LPOLESTR指向包含帮助文件名称的字符串的指针。

dwHelpContext

[in]DWORD包含帮助上下文标识符。

plResult

[out]指向LRESULT的指针,指出用户点击的按钮(取自MessageBoxIDxxx常量)。

 

返回值

 

返回以下值之一:

 

S_OK

主机显示其用户界面(UI)。MSHTML不显示其消息框。

S_FALSE

主机没有显示其UI。MSHTML显示其消息框。

 

 

托管浏览器控件时,您可以将Microsoft Internet Explorer消息框标题(用于Microsoft JScript警报(除其他外))替换为自己的应用程序的自定义标题。Internet Explorer消息框标题作为字符串资源存储在Shdoclc.dll中。它由符号IDS_MESSAGE_BOX_TITLE标识,值为2213。您可以自己加载该资源并将其与lpstrCaption值进行比较,以确定何时将消息框标题替换为您自己的自定义字符串。以下示例显示了一种实现IDocHostShowUI.ShowMessage的方法。

 

 

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;

}