As you probably already know, selecting a page of a tab control is usually best achieved by sending CTRL-TAB. So on opening an application we can use the following Macro Scheduler code to jump to the third tab:
SetFocus>Window_Title
Press CTRL
Press Tab * 2
Release CTRL
This issues CTRL-TAB twice and therefore cycles through two tab selections, leaving the third tab selected.
Usually when the window is first opened, the first tab is selected. But what if that is not always the case? How can we determine which tab is currently selected? This question came up in the forum recently.
To do this we can use the Windows API and send the TCM_GETCURSEL message to the tab control. When this message is sent to the control it returns the index of the selected tab.
Here’s an example. Right click on the desktop to open the Desktop Properties dialog and select one of the tabs to change the page. Then run this script:
//Initialise constants
Let>TCM_GETCURSEL=4875
//Get the handle of the Display Properties Window
GetWindowHandle>Display Properties,hwnd
//Find the handle of the SysTabControl32 (Tab Control) object
LibFunc>User32,FindWindowExA,tabctrl,hwnd,0,SysTabControl32,
//Send the TCM_GETCURSEL message to retrieve the selected tab index
LibFunc>user32,SendMessageA,tabindex,tabctrl,TCM_GETCURSEL,0,0
//Display the result
MessageModal>Selected Tab: %tabindex%
This finds the handle of the SysTabControl32 object on the Display Properties dialog and sends it the TCM_GETCURSEL message to retrieve the selected tab index.
You can use this approach with other applications. However, some applications use a different class of tab control, so you’d need to determine the class name of the tab control using the View System Windows tool in Macro Scheduler.