因为网页里有个ActiveX可能正在处理某项工作,我防止用户关机时,当前IE会被关掉,得到窗口句柄后,我可以接收到WM_POWERBROADCAST后,进行相应处理
能通过javascript得到吗?

解决方案 »

  1.   

    IHTMLDocument2* GetDocInterfaceByMSAA(HWND hwnd)
    {
    HRESULT hr;
    HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") ); IHTMLDocument2* pDoc2=NULL;
    if ( hInst != NULL ){
    if ( hwnd != NULL ){
    //取得AccessibleObjectFromWindow函数
    LPFNACCESSIBLEOBJECTFROMWINDOW pfAccessibleObjectFromWindow =
    (LPFNACCESSIBLEOBJECTFROMWINDOW)::GetProcAddress(hInst,_T("AccessibleObjectFromWindow"));
    if(pfAccessibleObjectFromWindow != NULL){
    CComPtr spAccess;
    hr=pfAccessibleObjectFromWindow(hwnd,0,
    IID_IAccessible,(void**) &spAccess);//取得Webbrowser控件的IAccessible接口
    if ( SUCCEEDED(hr) ){
    CComPtr spServiceProv;
    hr=spAccess->QueryInterface(IID_IServiceProvider,(void**)&spServiceProv);
    if(hr==S_OK){
    CComPtr spWin;
    hr=spServiceProv->QueryService(IID_IHTMLWindow2,IID_IHTMLWindow2,
    (void**)&spWin);
    /*
    注意:并不是每次都能取得IHTMLWindow2接口,如果调用失败,可以尝试取得IHTMLElement接口:
    CComPtr spElement;
    hr=spServiceProv->QueryService(IID_IHTMLElement,IID_IHTMLElement,(void**)&spElement);
    */
    if(hr==S_OK)
    spWin->get_document(&pDoc2);
    }
    }
    }
    }
    ::FreeLibrary(hInst);
    }
    else{
    AfxMessageBox(_T("请您安装Microsoft Active Accessibility"));
    }
    return pDoc2;
    }具体参见 VCKBASE Online Help Journal No.12 提个信息希望能帮助
      

  2.   

    通过IWebbrowser2接口可以得到IE的窗口
    PRB: Obtaining the HWND for the WebBrowser Control Q244310
    IOleWindow *pOWin;
    HWND hBWnd;HRESULT hRes = m_pBrowserApp->QueryInterface(IID_IOleWindow, (void **)&pOWin);
    if (SUCCEEDED(hRes)) {
        hRes = pOWin->GetWindow(&hBWnd);
        if (SUCCEEDED(hRes)) {
            // Place hBWnd-manipulating code here
        }
    }