得到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;
}

转载于:https://www.cnblogs.com/tanjian/articles/1633223.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值