VC浏览器相关的学习(四)(在BHO中获取IE版本以及获取窗体句柄)

值得注意的是IE6,IE7,IE8的窗体组织完全不一样,需要用VS自带的工具Spy++查看确定

a 获取IE版本

    int CMyRock::GetIEVersion() { CComPtr<IDispatch> pDocDisp; // Doc CComQIPtr<IHTMLDocument2> pHtmlDoc2; // HtmlDoc CComQIPtr<IHTMLWindow2> pWindow; // 窗体 CComQIPtr<IOmNavigator> pNavigator; // 浏览器 HRESULT hRes = m_spWebBrowser->get_Document(&pDocDisp); if(SUCCEEDED(hRes) && pDocDisp) { hRes = pDocDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pHtmlDoc2); if(SUCCEEDED(hRes) && pHtmlDoc2) { hRes = pHtmlDoc2->get_parentWindow(&pWindow); if(SUCCEEDED(hRes) && pWindow) { hRes = pWindow->get_navigator(&pNavigator); if(SUCCEEDED(hRes) && pNavigator) { CComBSTR bstrVersion; hRes = pNavigator->get_appVersion(&bstrVersion); if(SUCCEEDED(hRes)) { CHAR szVersion[MAX_PATH]; memset(szVersion,0,MAX_PATH); WideCharToMultiByte(CP_ACP, 0, bstrVersion.m_str, -1, szVersion, MAX_PATH, NULL, NULL); if(strstr(szVersion, "MSIE 7.") != 0) { m_nVersion = 7; } else if(strstr(szVersion, "MSIE 8.") != 0) { m_nVersion = 8; } } } } } } return m_nVersion; }

b IE8获取窗体句柄的例子

    HWND CMyRock::GetMenuParentIE8() { long nBrowser = 0; m_spWebBrowser->get_HWND(&nBrowser); HWND hWndParent = (HWND)nBrowser; HWND hWnd = GetWindow(hWndParent, GW_CHILD); // 查询主窗体,用SPY++看,会明白一些 if(hWnd) { TCHAR szClassName[MAX_PATH]; while(hWnd) { memset(szClassName,0,MAX_PATH); GetClassName(hWnd, szClassName, MAX_PATH); if(_tcscmp(szClassName,_T("Frame Tab"))==0) { // if(IsWindowVisible(hWnd)) { hWnd = GetWindow(hWnd, GW_CHILD); while(hWnd) { memset(szClassName, 0, MAX_PATH); GetClassName(hWnd, szClassName, MAX_PATH); if(_tcscmp(szClassName,_T("TabWindowClass"))==0) { hWnd = GetWindow(hWnd, GW_CHILD); while(hWnd) { memset(szClassName, 0, MAX_PATH); GetClassName(hWnd, szClassName, MAX_PATH); if(_tcscmp(szClassName,_T("Shell DocObject View"))==0) { hWnd = FindWindowEx(hWnd, NULL, _T("Internet Explorer_Server"), NULL); MessageBox(NULL, L"111", L"2222", 1); break; } hWnd = GetWindow(hWnd, GW_HWNDNEXT); } } hWnd = GetWindow(hWnd, GW_HWNDNEXT); } } } hWnd = GetWindow(hWnd, GW_HWNDNEXT); } } return hWnd; }

 

你可能感兴趣的:(浏览器,server,IE,null,Path,internet)