Here's a test script that might be useful for selecting a specific tab in a tab control and/or trying to determine if a control is assigned to a particular tab control. please feel free to comment, share tips, etc..
DetectHiddenWindows, On
Gui, Add, ListView, x10 y170 r20 c50 w580 h220 ggolv, ClassNN|HWND|Tab Control|Tab #|Text
Gui, Add, Tab, x16 y10 w250 h150 +0x2C2, Tab1|Tab2|Tab3
Gui, Add, Button, w100 h30,This is a test
Gui, Tab, Tab2
Gui, Add, Button, w100 h30,Ok
Gui, Add, Text,, This is another test control
Gui, Tab, Tab3
Gui, Add, Button, w100 h30,Cancel
Gui, Add, Tab, x276 y10 w310 h150 +0x108, TabA|TabB|TabC
Gui, Add, Progress ,, 50
Gui, Add, Button, w100 h30,Stop
Gui, Tab, TabB
Gui, Add, Button, w100 h30,Go
Gui, Tab, TabC
Gui, Add, Text, cred, Interesting...
Gui, Add, Button, x286 y60 w100 h30,Jump
Gui, Show, h400 w600, Tab Test
; **Get a list of controls in the window
Gui, +LastFound
WinGet, clist, ControlList
; ** init values
tcount = 0
TCM_SETCURSEL = 4876
TCM_GETITEMCOUNT = 0x1304
TCM_SETCURFOCUS = 0x1330
TCM_SETCURSEL = 0x130C
; ** loop through the controls in the list
Loop, Parse, clist, `n
{
; ** check if the control is a tab control
If (InStr(A_LoopField, "SysTabControl32")) {
; ** get the handle to the tab control
tabhwnd1 := GuiGetHWND(A_LoopField, "1")
; check for button style tabs
tabbtt=
WinGet, tabStyle, Style, ahk_id %tabhwnd1%
If (tabStyle & 0x100) { ; buttons are enabled - causes issues with selecting a specific tab
WinSet, Style, -0x100, ahk_id %tabhwnd1%
tabbtt = 1
}
; ** find out how many tabs the control has
tcount := DllCall("SendMessage", "UInt", tabhwnd1, "UInt", TCM_GETITEMCOUNT, Int, 0, Int, 0) - 1
; ** if the control only has one tab we shouldn't need to determine the tab number
If (tcount > 0) {
; Move to first tab
SendMessage, 0x1330, 0,0x0,, ahk_id %tabhwnd1% ; 0x1330 is TCM_SETCURFOCUS
SendMessage, 0x130C, 0,0x0,, ahk_id %tabhwnd1% ; 0x130C is TCM_SETCURSEL
; ** check if each control is visible
Loop, Parse, clist, `n
%A_LoopField% := DllCall("IsWindowVisible", "UInt", GuiGetHWND(A_LoopField, "1"))
; ** get the tab control number
numlen := StrLen(A_LoopField) - 15
StringRight, tnum, A_LoopField, %numlen%
Loop, %tcount%
{
cindex := A_Index + 1
; ** switch to each tab in the control
SendMessage, 0x1330, %A_Index%,0x0,, ahk_id %tabhwnd1% ; 0x1330 is TCM_SETCURFOCUS
SendMessage, 0x130C, %A_Index%,0x0,, ahk_id %tabhwnd1% ; 0x130C is TCM_SETCURSEL
; ** check which controls are visible
Loop, Parse, clist, `n
{
; ** If the control wasn't visible but is now visible - assume the control is assigned to this tab
IF (%A_LoopField% = "0" AND (DllCall("IsWindowVisible", "UInt", GuiGetHWND(A_LoopField, "1")) = 1)) {
%A_LoopField% = f
%A_LoopField%_tabc = %tnum%
%A_LoopField%_tab = %cindex%
}
; ** If the control was visible but now isn't - assume is assigned to Tab1
IF (%A_LoopField% = "1" AND (DllCall("IsWindowVisible", "UInt", GuiGetHWND(A_LoopField, "1")) = 0)) {
%A_LoopField% = f
%A_LoopField%_tabc = %tnum%
%A_LoopField%_tab = 1
}
}
}
; ** Move back to the first tab
SendMessage, 0x1330, 0,0x0,, ahk_id %tabhwnd1% ; 0x1330 is TCM_SETCURFOCUS
sleep, 0 ; to prevent redraw issues
SendMessage, 0x130C, 0,0x0,, ahk_id %tabhwnd1% ; 0x130C is TCM_SETCURSEL
If (tabbtt)
WinSet, Style, +0x100, ahk_id %tabhwnd1%
}
}
}
; ** Display the results in a ListView control
Loop, Parse, clist, `n
{
tabhwnd1 := GuiGetHWND(A_LoopField)
ControlGetText, ctxt,, ahk_id %tabhwnd1%
LV_Add("", A_LoopField, tabhwnd1, %A_LoopField%_tabc, %A_LoopField%_tab, ctxt)
}
Loop, 5
LV_ModifyCol(A_Index, "AutoHdr")
Return
; Select the tab containing the control when double-clicking an item in the ListView
golv:
If A_GuiEvent = DoubleClick
{
LV_GetText(ctrls, A_EventInfo, "3")
LV_GetText(tbbs, A_EventInfo, "4")
tbbs += -1
tabhwnd1 := GuiGetHWND("SysTabControl32" ctrls, "1")
tabbtt=
WinGet, tabStyle, Style, ahk_id %tabhwnd1%
If (tabStyle & 0x100) { ; buttons are enabled - causes issues with selecting a specific tab
WinSet, Style, -0x100, ahk_id %tabhwnd1%
tabbtt = 1
}
SendMessage, 0x1330, %tbbs%,, SysTabControl32%ctrls% ; 0x1330 is TCM_SETCURFOCUS
sleep, 0
SendMessage, 0x130C, %tbbs%,, SysTabControl32%ctrls% ; 0x130C is TCM_SETCURSEL
If (tabbtt)
WinSet, Style, +0x100, ahk_id %tabhwnd1%
}
Return
; ** function to retrieve HWNDs
GuiGetHWND(xxClassNN="", xxGUI=0)
{
If (xxGUI)
Gui, %xxGUI%:+LastFound
xxGui_hwnd := WinExist()
If xxClassNN=
Return, xxGui_hwnd
ControlGet, xxOutputVar, Hwnd,, %xxClassNN%, ahk_id %xxGui_hwnd%
Return, xxOutputVar
}
GuiClose:
ExitApp