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

枚举不出隐藏的选项卡,只能枚举出显示出来的选项卡
        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 count
	if(!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 ! skip
				continue;                               // another contorls
			tabsAccess=tabObject; // we found PageControl with IE7 tabs !
			hRes=tabsAccess->get_accChildCount(&TabsCount);  // number of opened tabs + New Tab button
					if(!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);
				}
			}
		} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值