得到alert的内容

要得到alert的内容可以通过实现IDocHostShowUI接口的ShowMessage方法来实现。

下面的例子来自MSDN

IDocHostShowUI::ShowMessage Method

--------------------------------------------------------------------------------

Called by MSHTML when it needs 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] HWND of the owner window.
lpstrText
[in] LPOLESTR pointer to a string containing the text for the message box.
lpstrCaption
[in] LPOLESTR pointer to a string containing the caption for the message box.
dwType
[in] DWORD containing the flag type (taken from the MessageBox MB_xxxx constants).
lpstrHelpFile
[in] LPOLESTR pointer to a string containing the Help file name.
dwHelpContext
[in] DWORD containing the Help context identifier.
plResult
[out] Pointer to an LRESULT which 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 user interface (UI). MSHTML does not display its message box.
S_FALSE Host did not display its UI. MSHTML displays its message box.


Example

When hosting the browser control, you can replace the Microsoft Internet Explorer message box caption (used for Microsoft JScript alerts (among other things) with a custom caption for your own application. 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 yourself and compare it with the lpstrCaption value to determine when to replace the message box caption with your own custom string. The following example shows one way you can implement IDocHostShowUI::ShowMessage to do this.

Security Alert Using LoadLibrary incorrectly can compromise the security of your application by loading the wrong dynamic-link library (DLL). Refer to the LoadLibrary documentation for information on how to correctly load DLLs with different versions of Microsoft Windows.

Hide Example

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;
}
posted @ 2006-07-21 15:58  huxi  阅读(518)  评论(0编辑  收藏  举报