描述:
我在网页中插入了一个MFC写的activex,在activex中能用什么方法来关闭自己以及当前的网页?
解决方案1:
call window.close from the activex
see
How To Retrieve the Top-Level IWebBrowser2 Interface from an ActiveX Control
http://support.microsoft.com/kb/257717
INFO: Accessing the Object Model from Within an ActiveX Control
http://support.microsoft.com/kb/172763
这个问题我回过一次,不过找不到了,把下面的代码写到CXXXXCtrl类的某一函数内:
void CXXXXCtrl::OnIECommand(int IECommand)
{
HWND hwndParent = 0, hFParent = 0;
m_pInPlaceSite->GetWindow(&hwndParent);
while (hwndParent)
{
hFParent = hwndParent;
hwndParent = ::GetParent(hwndParent);
}
if (hFParent)
{
UINT Command = 0;
switch (IECommand)
{
case 0: //关闭IE
Command = SC_CLOSE;
break;
case 1: //最小化IE
Command = SC_MINIMIZE;
break;
//还需要操作IE的其它方面,比如打印,一并写到这里即可
}
if (Command)
::PostMessage(hFParent, WM_SYSCOMMAND, Command, 0);
}
}