Ok I 1st created this to find a given sub window in an application. It looks more complicated than it is.
Actually its an example of how to find the windows hwnd so it can be used in a normal WinActivate.
I've used a sub window in MSVC++ as an example.
You can see the name of the sub window as Text2.
To make this work in your app, just change the winName to the visual text (Command Line) and the appName to the Window Title name
(both found in in AU3_Spy).
Once it's found the corresponding name, you will be prompted to click on the sub window.
Code:
winName = Text2 ; Change the name to the visible text title of the sub window.
appName = test - Microsoft Visual C++ ; Change the name to your main application.
WinGet, conList, ControlListHwnd, % appName
Loop, Parse, conList, `n
{
curHwnd := A_Loopfield
WinGetTitle, curWin, ahk_id %curHwnd%
CoordMode, Tooltip, Screen
tooltip % "Current Hwnd: " curHwnd "`nCurrent Window: " curWin, 10, 10
if (curWin = winName)
{
CoordMode, Tooltip, Screen
winHwnd := curHwnd
tooltip % "FOUND THE WINDOW!`n`nCurrent Hwnd: " winHwnd "`nCurrent Window: " curWin, 10, 10
sleep, 2000
Break
}
Sleep, 50
}
tooltip
Msgbox % "The hwnd is " winHwnd "`nNow use ahk_id `%winHwnd`% in WinActivate.`n`nPress Ok to select the window."
WinActivate, % appName
WinActivate, ahk_id %winHwnd%
Hopefully if that all works out, we've discovered how to find and select the window.
The reason its reliable is because most applications (if not all) create a new HWND (ahk_id) each time the application is open or the sub window is closed and reopened.
For this reason, you must find the HWND name before trying to select the window. Trying to use one single HWND will not work 99.9% of the time.
Now, this method can be condensed into:
Code:
winName = Text2 ; Change the name to the visible text title of the sub window.
appName = test - Microsoft Visual C++ ; Change the name to your main application.
WinGet, conList, ControlListHwnd, % appName
Loop, Parse, conList, `n
{
curHwnd := A_Loopfield
WinGetTitle, curWin, ahk_id %curHwnd%
CoordMode, Tooltip, Screen
if (curWin = winName)
Break
}
WinActivate, % appName
WinActivate, ahk_id %curHwnd%
This will act like a single winactive for the sub window and should be quite fast if not instant.
NOTE: You may not have to activate the main application window before selecting the sub window, I just did this for my own reference

.
hth