多TAB下让某个页面提前

来源:互联网 发布:淘宝店铺店招怎么制作 编辑:程序博客网 时间:2024/05/01 15:04

转帖

 

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=743273&SiteID=1
found   solution.   Spicific   IE7   tab   can   be   set   as   active   via   Active   Accessability   !

This   is   my   very   very   first   experemental   but   !!!WORKING!!!   code   !
I   write   it   under   BDS   2006,   but   it 's   must   work   under   Visual   studio   to.

I   hope   it 's   helps:

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);
                        }
                }
        }
}