得到了IWebBrowser2 接口,怎么让IE跳转到相应的页面

 我来答
若以下回答无法解决问题,邀请你更新回答
就烦条0o
2016-12-31 · 知道合伙人软件行家
就烦条0o
知道合伙人软件行家
采纳数:33315 获赞数:46492
从事多年系统运维,喜欢编写各种小程序和脚本。

向TA提问 私信TA
展开全部
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);
}
}
}
}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式