jiangsheng我在程序中host住了WebBrowser,但网页中有类似window.close()的脚本....

zmxjh 2002-05-14 03:58:47
我在程序中host住了WebBrowser,但网页中有类似window.close()的脚本执行时,
我的程序不能够像IE那样关闭,而是一片空白,我怎么解决这个问题。

我同时查了一个msdn,发现在IE5.5中的Webbrowser2有一个windowcloseing事件可以
办到,但我想到ie5.0版本中就做到类似的功能,是不是也可以。如果不可能,那么ie5.0里面是怎么做的。

谢谢。
...全文
56 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2002-05-15
  • 打赏
  • 举报
回复
RESOLUTION
In Internet Explorer 5.5, the WebBrowser control's default source interface, DWebBrowserEvents2, exposes a new event called WindowClosing. You can sink DWebBrowserEvents2 and set the Cancel parameter of the event to TRUE to prevent the close from occurring, or you can close the host windows.

In Internet Explorer 5.01 and earlier, the WM_PARENTNOTIFY message is sent to the parent of a child window when the child window is created or destroyed, or when the user clicks a mouse button while the cursor is over the child window. Thus, the hosting container of the WebBrowser control can watch for a WM_DESTROY notification message. If LOWORD of the wParam field of the WM_PARENTNOTIFY message is set to WM_DESTROY, the HIWORD of wParam contains the child window identifier, and the lParam field contains the hWnd of the child control. If the hWnd in lParam matches the hWnd of the WebBrowser control, you can determine that the WebBrowser control is being destroyed. You can then take the appropriate action, which typically means to close the child window for multiple-document interface (MDI) applications and quit the applications for single-document interface (SDI) applications.
When the script calls window.close, the WebBrowser control destroys its window, but the control is still in its "running" state (that is, the control is not completely destroyed). The WebBrowser control does not inform its container on deactivation through the IOleInPlaceSite::OnUIDeactivate method.

Handling the WM_PARENTNOTIFY message
Add a handler prototype for the OnParentNotify function to the CHtmlView-derived class:



afx_msg void OnParentNotify( UINT message, LPARAM lParam );
Add a WM_PARENTNOTIFY handler to the message map:



BEGIN_MESSAGE_MAP(CQ253219View, CHtmlView)
.
.
ON_WM_PARENTNOTIFY()
.
.
END_MESSAGE_MAP()
Implement the WM_PARENTNOTIFY event handler. For example:



void CQ253219View::OnParentNotify(UINT message, LPARAM lParam )
{
if ((LOWORD(message) == WM_DESTROY) && ((HWND)lParam == m_wndBrowser))
{
// Close the parent frame window.
GetParentFrame()->PostMessage(WM_CLOSE, 0, 0);
}
else
CHtmlView::OnParentNotify(message, lParam );
}

zmxjh 2002-05-15
  • 打赏
  • 举报
回复
关注

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧