The method of selecting a specific tab that is mentioned seems to be incomplete unfortunately. On this system (Win XP pro SP2) it seems that a couple calls are necessary to switch to a specific tab. TCM_SETCURSEL will switch to the tab by itself but the contents of the tab won't change. Sending a TCM_SETCURFOCUS message and sleep, 0 first seems to work well in most cases. This method doesn't seem to work when the tab control has TCS_BUTTONS style though so it seems to be necessary to temporarily modify the style.TabLeft [, Count]: Moves left by one or more tabs in a SysTabControl32. Count is assumed to be 1 if omitted or blank. To instead select a tab directly by number, replace the number 5 below with one less than the tab number you wish to select. In other words, 0 selects the first tab, 1 selects the second, and so on:
SendMessage, 0x130C, 5,, SysTabControl321, WinTitle ; 0x130C is TCM_SETCURSEL.
Here's a function that seems to work ok:
SwitchToTabN(t_TabControl, t_TabNumber, t_Wintitle="") { If t_TabControl is not number ControlGet, t_TabControl, Hwnd,, %t_TabControl%, %t_WinTitle% WinGet, t_tabStyle, Style, ahk_id %t_TabControl% If (t_tabStyle & 0x100) { ; buttons are enabled - remove TCS_BUTTONS style WinSet, Style, -0x100, ahk_id %t_TabControl% t_tbuttons = 1 } SendMessage, 0x1330, %t_TabNumber%,,, ahk_id %t_TabControl% ; 0x1330 is TCM_SETCURFOCUS sleep, 0 ; to prevent redraw issues SendMessage, 0x130C, %t_TabNumber%,,, ahk_id %t_TabControl% ; 0x130C is TCM_SETCURSEL If (t_tbuttons) WinSet, Style, +0x100, ahk_id %t_TabControl% }
t_TabControl - either the HWND or classNN of the tab control
t_TabNumber - the index of the tab to switch to
t_Wintitle - if a classNN is specified for t_TabControl then a Window title can optionally be specified
Could this function (or similar) be added to the documentation or the functionality be built in? If built in, maybe as a Tab, N option?