An application with a main window winA generates a small popup window winB each time a particular function Func is activated. The small window is not often needed and I would like it to be hidden unless I am actually using it. But sometimes I need to unhide it. And I also need to close it. So I wrote a set of 3 macros, using hotkeys F1,F2,F3:
Code:
#IfWinActive ;No matter which window is on top
F1:: Perform Func and allow winB to be on top, i.e., visible
DetectHiddenWindows, On ;Off by default
IfWinExist, winB ;If winB window already exists (means Func is already running)
;IF winB ALREADY EXISTS AND IS VISIBLE, I SHOULDN'T HAVE TO
;WASTE TIME BY RUNNING THE NEXT LINE!
WinShow, winB ;Unhide window
Else ;winB window needs to be created
Gosub, RunFunc ;Includes creating winB
DetectHiddenWindows, Off
Return
;----------------
#IfWinActive ;No matter which window is on top
F2:: ;Perform Func but hide winB
DetectHiddenWindows, On ;Off by default
IfWinNotExist, winB ;First create winB, then hide it
{
IfWinNotActive, winA
{
WinActivate, winA ;Main Window must be active
WinWaitActive, winA
}
Gosub, RunFunc ;Includes creating winB
WinWaitActive, winB
}
WinHide, winB ;Hide window
DetectHiddenWindows, Off
Return
;----------------
F3:: Kill winB when finished
DetectHiddenWindows, On
IfWinExist, winB
WinClose, winB
DetectHiddenWindows, Off
Return
RunFunc: ;Activate app's Func function which also creates popup winB
;some code
Return
The real version of this code works quite well, but I'm always trying to make it as rigorous as possible, hence this problem.
I can't find any simple way in AHK to ascertain whether a window which exists is hidden or not. In this example, I don't need to unhide it if I know it exists and it's on top. All I should need to do is use WinActivate, maybe, instead of WinShow. Can someone explain the difference between them and also suggest a way of determining whether a window is hidden so that I don't have to WinShow it if there's no need.
The only solution I've found here in the forum is
http://www.autohotkey.com/forum/topic3135.html
but it looks too complex and I'm not sure how I'd fit it into my code.
Thanks for any assistance.