AHK_L IE COM Question

Get help with using AutoHotkey and its commands and hotkeys
c4p
Posts: 17
Joined: 18 Jan 2017, 18:38

AHK_L IE COM Question

30 Mar 2017, 18:30

I am looking to manipulate Jethow's IE COM functions (IEGet, WBGet, TabActivate, etc) using IE 11 in order to find/activate/return pointer for existing pages via tab name, otherwise open it as a new tab. I have pieced together this code which seems to work fine if I am on the browser instance which includes the tab I am after (or if that is the only instance of IE), however if there is another IE instance without the target, the function starts a new page incorrectly. Thanks for looking. :)

Code: Select all

#SingleInstance, Force
#Persistent
#Include Acc.ahk

^f::
wb := IEGo("http://www.google.com","Google")
if wb
	wb.Refresh
return

IEGo(URL, TabName := "") { 
  if (TabName) {  ; Search for pre-existing ie tab
    For wb in ComObjCreate("Shell.Application").Windows {
      If  wb.LocationName= TabName and InStr(wb.FullName, "iexplore.exe") {
        window:=0, client:=-4 ; constants for ie 11, varies on other versions
        ControlGet hwnd, hwnd, , DirectUIHWND2, ahk_class IEFrame ; get control hwnd
        client := Acc_ObjectFromWindow(hwnd, client) ;note - the client object should be the 4th child of the window
        page_tab_list := Acc_Children(client)[1]
        for each, child in Acc_Children(page_tab_list) {
          if InStr(child.accName(0),TabName) {
            child.accDoDefaultAction(0) ; Selects correct tab
            Winactivate, ahk_id %hwnd% ; Activates the IE Window
            return wb
          }
        }
      }
    }
  }
  ; No ie tab found, so create it
  wb := ComObjCreate("InternetExplorer.Application")
  wb.Visible := True
  if URL, wb.Navigate(URL)
  return wb
}
User avatar
Blackholyman
Posts: 1281
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: AHK_L IE COM Question

31 Mar 2017, 01:12

Code: Select all

#SingleInstance, Force
#Persistent
#Include Acc.ahk

^f::
wb := IEGo("http://www.google.com","Google")
if wb
   wb.Refresh
return

IEGo(URL, TabName := "") 
{ 
   if (TabName) 
   {  ; Search for pre-existing ie tab
      For wb in ComObjCreate("Shell.Application").Windows 
      {
         If  wb.LocationName= TabName and InStr(wb.FullName, "iexplore.exe") 
         {
            window:=0, client:=-4 ; constants for ie 11, varies on other versions
            ControlGet hwnd, hwnd, , DirectUIHWND1, % "ahk_class IEFrame ahk_id " wb.hwnd ; get control hwnd
            client := Acc_ObjectFromWindow(hwnd, client) ;note - the client object should be the 4th child of the window
            page_tab_list := Acc_Children(client)[1]
            for each, child in Acc_Children(page_tab_list) 
            {
               if InStr(child.accName(0),TabName) 
               {
                  child.accDoDefaultAction(0) ; Selects correct tab
                  Winactivate, ahk_id %hwnd% ; Activates the IE Window
                  return wb
               }
            }
         }
      }
   }
   ; No ie tab found, so create it
   wb := ComObjCreate("InternetExplorer.Application")
   wb.Visible := True
   if URL
   {
      wb.Navigate(URL)
      while wb.busy
         sleep 100
   }
   return wb
}
biggest change was in this line ControlGet hwnd, hwnd, , DirectUIHWND1, % "ahk_class IEFrame ahk_id " wb.hwnd

this " DirectUIHWND1" may or may not change unsure did not test for long
c4p
Posts: 17
Joined: 18 Jan 2017, 18:38

Re: AHK_L IE COM Question

31 Mar 2017, 15:05

Thanks, needed DirectUIHWND2, but after that it works perfectly.
Working Code: AHK_L using IE 11

Code: Select all

#SingleInstance, Force
#Persistent
#Include Acc.ahk ; https://autohotkey.com/board/topic/77303-acc-library-ahk-l-updated-09272012/

^f::
wb := IEGo("http://www.google.com","Google")
if wb
   wb.Refresh
return

IEGo(URL, TabName := "") 
{ 
   if (TabName) 
   {  ; Search for pre-existing ie tab
      For wb in ComObjCreate("Shell.Application").Windows 
      {
         If  wb.LocationName= TabName and InStr(wb.FullName, "iexplore.exe") 
         {
            window:=0, client:=-4 ; constants for ie 11, varies on other versions
            ControlGet hwnd, hwnd, , DirectUIHWND2, % "ahk_class IEFrame ahk_id " wb.hwnd ; get control hwnd
            client := Acc_ObjectFromWindow(hwnd, client) ;note - the client object should be the 4th child of the window
            page_tab_list := Acc_Children(client)[1]
            for each, child in Acc_Children(page_tab_list) 
            {
               if InStr(child.accName(0),TabName) 
               {
                  child.accDoDefaultAction(0) ; Selects correct tab
                  Winactivate, ahk_id %hwnd% ; Activates the IE Window
                  return wb
               }
            }
         }
      }
   }
   ; No ie tab found, so create it
   wb := ComObjCreate("InternetExplorer.Application")
   wb.Visible := True
   if URL
   {
      wb.Navigate(URL)
      while wb.busy
         sleep 100
   }
   return wb
}

Return to “Ask For Help”

Who is online

Users browsing this forum: A_Perry_1984, Bing [Bot], Google [Bot], labrint, maxkill, Mipha, nacken012, relativity, Rohwedder, teadrinker and 213 guests