I have here 8 functions, intended to work similarly to the functions for Firefox and Chrome:
Unfortunately although a lot of things are doable in Internet Explorer, I have had a lot of problems trying to activate a tab in Internet Explorer. It's possible to loop through the Internet Explorer_Server controls in Internet Explorer, and retrieve the titles/urls, however, even though you might have the control hWnd, I'm not sure of a method to then focus the tab.
Methods to activate a tab work as follows: activate a TabThumbnailWindow window (if you know the title), or, use Acc to invoke the activation of one of the tabs you can see listed on the screen, or, navigate using ctrl+tab to a tab you can't see (when there are too many tabs for Internet Explorer to show all at the same time (if you know the title or url).
Code: Select all
;based on Acc applied to the visible tabs (if there are too many tabs open, Internet Explorer only shows some tabs in the header row)
;JEE_IntExpGetVisTabCount(hWnd)
;JEE_IntExpGetVisTabNames(hWnd, vSep:="`n", vMode:="t", vSep2:="`t")
;JEE_IntExpFocusVisTabByNum(hWnd, vNum)
;JEE_IntExpFocusVisTabByName(hWnd, vTitle, vNum:=1, vUseDesc:=0)
;based on COM or sending ctrl+num/(shift+)ctrl+tab or activating a TabThumbnailWindow window
;JEE_IntExpGetTabCount(hWnd:=-1)
;JEE_IntExpGetTabNames(hWnd, vSep:="`n", vMode:="t", vSep2:="`t")
;JEE_IntExpFocusTabByNum(hWnd, vNum)
;JEE_IntExpFocusTabByName(hWnd, vTitle, vNum:=1)
;==================================================
JEE_IntExpGetVisTabCount(hWnd)
{
ControlGet, hCtl, Hwnd,, TabBandClass1, % "ahk_id " hWnd
oAcc := Acc_Get("Object", "4.1.4.1", 0, "ahk_id " hCtl)
for _, oChild in Acc_Children(oAcc)
{
vTabText := oChild.accName(0)
if (vTabText == "Scroll tab list backward")
|| (vTabText == "Scroll tab list forward")
|| (vTabText == "New tab (Ctrl+T)")
continue
vCount++
}
oAcc := oChild := ""
return vCount
}
;==================================================
JEE_IntExpGetVisTabNames(hWnd, vSep:="`n", vMode:="t", vSep2:="`t")
{
ControlGet, hCtl, Hwnd,, TabBandClass1, % "ahk_id " hWnd
oAcc := Acc_Get("Object", "4.1.4.1", 0, "ahk_id " hCtl)
vOutput := ""
for _, oChild in Acc_Children(oAcc)
{
vTabText := oChild.accName(0)
if (vTabText == "Scroll tab list backward")
|| (vTabText == "Scroll tab list forward")
|| (vTabText == "New tab (Ctrl+T)")
continue
oTemp := StrSplit(oChild.accDescription(0), "`r`n")
if (vMode = "t")
vOutput .= oTemp.1 vSep
else if (vMode = "tu")
vOutput .= oTemp.1 vSep2 oTemp.2 vSep
else if (vMode = "u")
vOutput .= oTemp.2 vSep
else if (vMode = "ut")
vOutput .= oTemp.2 vSep2 oTemp.1 vSep
}
vOutput := SubStr(vOutput, 1, -StrLen(vSep))
oAcc := oChild := oTemp := ""
return vOutput
}
;==================================================
JEE_IntExpFocusVisTabByNum(hWnd, vNum)
{
ControlGet, hCtl, Hwnd,, TabBandClass1, % "ahk_id " hWnd
oAcc := Acc_Get("Object", "4.1.4.1", 0, "ahk_id " hCtl)
vCount := 0, vRet := 0
for _, oChild in Acc_Children(oAcc)
{
vTabText := oChild.accName(0)
if (vTabText == "Scroll tab list backward")
|| (vTabText == "Scroll tab list forward")
|| (vTabText == "New tab (Ctrl+T)")
continue
vCount++
if (vNum = vCount)
{
oChild.accDoDefaultAction(0), vRet := vNum
break
}
}
oAcc := oChild := ""
return vRet
}
;==================================================
;WinGet, hWnd, ID, ahk_class IEFrame
;vTitle1 := "Google"
;vTitle2 := "Google" "`r`n" "https://www.google.co.uk/"
;JEE_IntExpFocusVisTabByName(hWnd, vTitle1)
;JEE_IntExpFocusVisTabByName(hWnd, vTitle2, 1, 1)
;return
JEE_IntExpFocusVisTabByName(hWnd, vTitle, vNum:=1, vUseDesc:=0)
{
ControlGet, hCtl, Hwnd,, TabBandClass1, % "ahk_id " hWnd
oAcc := Acc_Get("Object", "4.1.4.1", 0, "ahk_id " hCtl)
vCount := 0, vRet := 0
for _, oChild in Acc_Children(oAcc)
{
if !vUseDesc
vTabText := oChild.accName(0)
else
vTabText := oChild.accDescription(0)
if (vTabText = vTitle)
vCount++
if (vCount = vNum)
{
oChild.accDoDefaultAction(0), vRet := vCount
break
}
}
oAcc := oChild := ""
return vRet
}
;==================================================
JEE_IntExpGetTabCount(hWnd:=-1)
{
vCount := 0
for oWin in ComObjCreate("Shell.Application").Windows
if (hWnd = oWin.HWND)
|| ((hWnd = -1) && (oWin.Name = "Internet Explorer"))
vCount++
return vCount
}
;==================================================
;vMode: e.g. htud,
;h=hWnd (hex), t=title, u=url, h=hWnd (dec)
JEE_IntExpGetTabNames(hWnd, vSep:="`n", vMode:="t", vSep2:="`t")
{
vOutput := ""
for oWin in ComObjCreate("Shell.Application").Windows
if (hWnd = oWin.HWND)
|| ((hWnd = -1) && (oWin.Name = "Internet Explorer"))
{
Loop, Parse, vMode
{
if (A_LoopField = "t")
vOutput .= oWin.document.title
else if (A_LoopField = "u")
vOutput .= oWin.document.url
else if (A_LoopField = "h")
vOutput .= Format("0x{:x}", oWin.HWND)
else if (A_LoopField = "d")
vOutput .= oWin.HWND
vOutput .= A_Index=StrLen(vMode)?vSep:vSep2
}
}
return vOutput
}
;==================================================
;the function is currently limited by the use of SendInput
;since the use ControlSend or an equivalent has so far failed
JEE_IntExpFocusTabByNum(hWnd, vNum)
{
if !WinActive("ahk_id " hWnd)
WinActivate, % "ahk_id " hWnd
if (vNum > 1) && (vNum < 8)
SendInput, % "^" vNum
else if (vNum = (vCount := JEE_IntExpGetTabCount(hWnd)))
SendInput, ^9
else if (vNum - 8 <= vCount - vNum)
{
SendInput, ^8
Sleep 100
Loop, % vNum - 8
{
SendInput, ^{Tab}
Sleep 100
}
}
else
{
SendInput, ^9
Sleep 100
Loop, % vCount - vNum
{
SendInput, ^+{Tab}
Sleep 100
}
}
}
;==================================================
;hWnd parameter is currently redundant, but kept for potential future use
;and to match other functions
JEE_IntExpFocusTabByName(hWnd, vTitle, vNum:=1)
{
DetectHiddenWindows, On
WinGet, vWinList, List, ahk_class TabThumbnailWindow
vCount := 0
Loop, % vWinList
{
hWnd := vWinList%A_Index%
WinGetTitle, vWinTitle, % "ahk_id " hWnd
if !(vWinTitle = vTitle " - Internet Explorer")
continue
vCount++
if !(vCount = vNum)
continue
ControlSend, ahk_parent, {Alt Down}{Alt Up}{Alt Down}{Alt Up}, % "ahk_id " hWnd
DllCall("user32\SetForegroundWindow", Ptr,hWnd)
break
}
}
;==================================================