得到了IWebBrowser2 接口,怎么让IE跳转到相应的页面
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
void __fastcall TForm1::ActivateTab(TObject *Sender)
{
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[10],tabStruct[10],tabQueryStruct,tabResStruct;
tabQueryStruct.vt=VT_I4;
tabQueryStruct.lVal=CHILDID_SELF;
/*
IE7 windows tree:
IEFrame
|
--CommandBarClass
|
--ReBarWindow32
|
--TabBandClass
|
--DirectUIHWND < < < < < IE 7 Tabs here !!!
*/
MainIEWnd=FindWindow( "IEFrame ",NULL);
if(!MainIEWnd)
{
ShowMessage( "DEBUG: Unable to find main IE window ");
return;
}
CommandBarWnd=FindWindowEx(MainIEWnd,NULL, "CommandBarClass ",NULL);
if(!CommandBarWnd)
{
ShowMessage( "DEBUG: Unable to find CommandBarWindow ");
return;
}
ReBarWnd=FindWindowEx(CommandBarWnd,NULL, "ReBarWindow32 ",NULL);
if(!ReBarWnd)
{
ShowMessage( "DEBUG: Unable to find ReBarWindow32 ");
return;
}
TabBandWnd=FindWindowEx(ReBarWnd,NULL, "TabBandClass ",NULL);
if(!TabBandWnd)
{
ShowMessage( "DEBUG: Unable to find TabBandClass ");
return;
}
DirectUIWnd=FindWindowEx(TabBandWnd,NULL, "DirectUIHWND ",NULL);
if(!DirectUIWnd)
{
ShowMessage( "DEBUG: Unable to find DirectUIHWND ");
return;
}
if(AccessibleObjectFromWindow(DirectUIWnd,OBJID_CLIENT,IID_IAccessible,(void **)&tabsAccess)!=S_OK)
{
ShowMessage( "DEBUG: Unable to get IAccessible interface ");
return;
}
hRes=tabsAccess-> get_accChildCount(&TabsCount); // get objects count
if(!SUCCEEDED(hRes))
{
ShowMessage( "DEBUG: Unable to get Objects count ");
return;
}
hRes=AccessibleChildren(tabsAccess,0,TabsCount,ChildStruct,&TabsReceived);
if(!SUCCEEDED(hRes))
{
ShowMessage( "DEBUG: Unable to get objects ");
return;
}
for(int i=0;i <TabsReceived;i++) // enum objects
{
if(ChildStruct.vt==VT_DISPATCH)
{
tabDisp=ChildStruct.pdispVal;
hRes=tabDisp-> QueryInterface(IID_IAccessible,(void **)&tabObject);
if(!SUCCEEDED(hRes))
{
ShowMessage( "DEBUG: QueryInterface to tabObject failed ");
continue;
}
hRes=tabObject-> get_accRole(tabQueryStruct,&tabResStruct);
if(!SUCCEEDED(hRes))
{
ShowMessage( "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))
{
ShowMessage( "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))
{
ShowMessage( "DEBUG: QueryInterface to newObj failed ");
continue;
}
hRes=newObj-> get_accName(tabQueryStruct,&tabCaption);
if(!SUCCEEDED(hRes))
{
ShowMessage( "DEBUG: Unable to receive tab caption ");
continue;
}
if(tabCaption==L "your specific string ")
// make this f..g tab active !!!!
newObj-> accDoDefaultAction(tabQueryStruct);
}
}
}
}
{
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[10],tabStruct[10],tabQueryStruct,tabResStruct;
tabQueryStruct.vt=VT_I4;
tabQueryStruct.lVal=CHILDID_SELF;
/*
IE7 windows tree:
IEFrame
|
--CommandBarClass
|
--ReBarWindow32
|
--TabBandClass
|
--DirectUIHWND < < < < < IE 7 Tabs here !!!
*/
MainIEWnd=FindWindow( "IEFrame ",NULL);
if(!MainIEWnd)
{
ShowMessage( "DEBUG: Unable to find main IE window ");
return;
}
CommandBarWnd=FindWindowEx(MainIEWnd,NULL, "CommandBarClass ",NULL);
if(!CommandBarWnd)
{
ShowMessage( "DEBUG: Unable to find CommandBarWindow ");
return;
}
ReBarWnd=FindWindowEx(CommandBarWnd,NULL, "ReBarWindow32 ",NULL);
if(!ReBarWnd)
{
ShowMessage( "DEBUG: Unable to find ReBarWindow32 ");
return;
}
TabBandWnd=FindWindowEx(ReBarWnd,NULL, "TabBandClass ",NULL);
if(!TabBandWnd)
{
ShowMessage( "DEBUG: Unable to find TabBandClass ");
return;
}
DirectUIWnd=FindWindowEx(TabBandWnd,NULL, "DirectUIHWND ",NULL);
if(!DirectUIWnd)
{
ShowMessage( "DEBUG: Unable to find DirectUIHWND ");
return;
}
if(AccessibleObjectFromWindow(DirectUIWnd,OBJID_CLIENT,IID_IAccessible,(void **)&tabsAccess)!=S_OK)
{
ShowMessage( "DEBUG: Unable to get IAccessible interface ");
return;
}
hRes=tabsAccess-> get_accChildCount(&TabsCount); // get objects count
if(!SUCCEEDED(hRes))
{
ShowMessage( "DEBUG: Unable to get Objects count ");
return;
}
hRes=AccessibleChildren(tabsAccess,0,TabsCount,ChildStruct,&TabsReceived);
if(!SUCCEEDED(hRes))
{
ShowMessage( "DEBUG: Unable to get objects ");
return;
}
for(int i=0;i <TabsReceived;i++) // enum objects
{
if(ChildStruct.vt==VT_DISPATCH)
{
tabDisp=ChildStruct.pdispVal;
hRes=tabDisp-> QueryInterface(IID_IAccessible,(void **)&tabObject);
if(!SUCCEEDED(hRes))
{
ShowMessage( "DEBUG: QueryInterface to tabObject failed ");
continue;
}
hRes=tabObject-> get_accRole(tabQueryStruct,&tabResStruct);
if(!SUCCEEDED(hRes))
{
ShowMessage( "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))
{
ShowMessage( "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))
{
ShowMessage( "DEBUG: QueryInterface to newObj failed ");
continue;
}
hRes=newObj-> get_accName(tabQueryStruct,&tabCaption);
if(!SUCCEEDED(hRes))
{
ShowMessage( "DEBUG: Unable to receive tab caption ");
continue;
}
if(tabCaption==L "your specific string ")
// make this f..g tab active !!!!
newObj-> accDoDefaultAction(tabQueryStruct);
}
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询