COM 通过查找IE窗口切换IE选项卡

来源:互联网 发布:adobe flash mac版 编辑:程序博客网 时间:2024/06/12 23:59
枚举不出隐藏的选项卡,只能枚举出显示出来的选项卡        HRESULT hRes;HWND MainIEWnd;HWND CommandBarWnd;HWND ReBarWnd;HWND TabBandWnd;HWND DirectUIWnd;BSTR tabCaption;long TabsCount=0,TabsReceived=0,newRes;IAccessible *tabsAccess,*tabObject,*newObj;IDispatch *tabDisp,*tab1;VARIANT ChildStruct[MAX_PATH],tabStruct[MAX_PATH],tabQueryStruct,tabResStruct;tabQueryStruct.vt=VT_I4;tabQueryStruct.lVal=CHILDID_SELF;MainIEWnd=::FindWindow(L"IEFrame",NULL);if(!MainIEWnd){AfxMessageBox(L"DEBUG: Unable to find main IE window");return;}CommandBarWnd=::FindWindowEx(MainIEWnd,NULL,L"WorkerW",NULL);if(!CommandBarWnd){AfxMessageBox(L"DEBUG: Unable to find CommandBarWindow");return;}ReBarWnd=::FindWindowEx(CommandBarWnd,NULL,L"ReBarWindow32",NULL);if(!ReBarWnd){AfxMessageBox(L"DEBUG: Unable to find ReBarWindow32");return;}TabBandWnd=::FindWindowEx(ReBarWnd,NULL,L"TabBandClass",NULL);DWORD n = GetLastError();if(!TabBandWnd){CString Str;Str.Format(L"%d", n);AfxMessageBox(L"DEBUG: Unable to find TabBandClass" + Str);return;}DirectUIWnd=::FindWindowEx(TabBandWnd,NULL,L"DirectUIHWND",NULL);n = GetLastError();if(!DirectUIWnd){CString Str;Str.Format(L"%d", n);AfxMessageBox(L"DEBUG: Unable to find DirectUIHWND" + Str);return;}if(AccessibleObjectFromWindow(DirectUIWnd,OBJID_CLIENT,IID_IAccessible,(void **)&tabsAccess)!=S_OK){AfxMessageBox(L"DEBUG: Unable to get IAccessible interface");return;}hRes=tabsAccess->get_accChildCount(&TabsCount); // get objects countif(!SUCCEEDED(hRes)){AfxMessageBox(L"DEBUG: Unable to get Objects count");return;}hRes=AccessibleChildren(tabsAccess,0,TabsCount,ChildStruct,&TabsReceived);if(!SUCCEEDED(hRes)){AfxMessageBox(L"DEBUG: Unable to get objects");return;}for(int i=0;i<TabsReceived;i++) // enum objects{if(ChildStruct[i].vt==VT_DISPATCH){tabDisp=ChildStruct[i].pdispVal;hRes=tabDisp->QueryInterface(IID_IAccessible,(void **)&tabObject);if(!SUCCEEDED(hRes)){AfxMessageBox(L"DEBUG: QueryInterface to tabObject failed");continue;}hRes=tabObject->get_accRole(tabQueryStruct,&tabResStruct);if(!SUCCEEDED(hRes)){AfxMessageBox(L"DEBUG: Unable to receive object role");continue;}if(tabResStruct.lVal!=ROLE_SYSTEM_PAGETABLIST)  // we need only PageControl ! skipcontinue;                               // another contorlstabsAccess=tabObject; // we found PageControl with IE7 tabs !hRes=tabsAccess->get_accChildCount(&TabsCount);  // number of opened tabs + New Tab buttonif(!SUCCEEDED(hRes)){AfxMessageBox(L"DEBUG: tab count failed");continue;}hRes=AccessibleChildren(tabsAccess,0,TabsCount,tabStruct,&newRes);for(int j=0;j<newRes;j++)   // enum tabs{tab1=tabStruct[j].pdispVal;hRes=tab1->QueryInterface(IID_IAccessible,(void **)&newObj);if(!SUCCEEDED(hRes)){AfxMessageBox(L"DEBUG: QueryInterface to newObj failed");continue;} hRes=newObj->get_accName(tabQueryStruct,&tabCaption); if(!SUCCEEDED(hRes)){AfxMessageBox(L"DEBUG: Unable to receive tab caption");continue;} CString StrCaption = tabCaption;if(wcscmp(StrCaption, L"hao123_上网从这里开始") == 0)// make this f..g tab active !!!!newObj->accDoDefaultAction(tabQueryStruct);}}} 

原创粉丝点击