;Function to return if window is hidden or not, change, or toggle state. ;; Param 1: Check/Change ; Check - Returns -1 if window does not exist ; Returns 0 if window is hidden ; Returns 1 If Window is showing ; Change - Returns -1 if Window does not exist ; Returns 0 if Windows final state is Hidden ; Returns 1 If Windows final state is Showing ;######################################################## ;; Param 6: Effect ; 0 (zero) - Hides window ; 1 (one) - Shows window ; 2 (two) - Toggles current state. WinInView(Action, WinTitle, WinText="", ExcludeTitle="", ExcludeText="", Effect="") { DHWState = %A_DetectHiddenWindows% If Action Not in Check,Change { Result = Error Return Result } DetectHiddenWindows, On IfWinNotExist, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% Result = -1 ;Else If Window Exists IfWinExist, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% { DetectHiddenWindows, Off WinGetPos, WinX,,,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;If Window is hidden If WinX = Result = 0 ;If Window is showing Else Result = 1 } If Action = Change { ;Confirm Effect to take place, Return Error if None. If Effect Not between 0 and 2 { Result = Error Return Result } ;Show the window if it hidden If (Effect = 1) OR (Result = 0 AND Effect = 2) { WinShow, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% Result = 1 Return Result } ;Hide the window if it is shown If (Effect = 0) OR (Result = 1 AND Effect = 2) { WinHide, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% Result = 0 Return Result } } DetectHiddenWindows, %DHWState% Return Result }
Syntax:
WinInView( Check|Change, WinTitle, [WinText, ExcludeTitle, ExcludeText, Effect])
Can be used to see if:
Window exists
Window is Hidden
Window is Show
Show Window
Hide Window
Toggle current State(if its hidden, show it; otherwise hide it)
Note, if Param1 is "Change" and Param6 is blank or not suppoted "Error" is returned. good Ex:
WinInView(Change, "ThisWindow", "", "", "", "", "2")
If Param1 is not supported, "Error" is returned
Working Example:
;Function to return if window is hidden or not ;Options toggle,Hide,Show Gui, Add, Text, UIDtext Gui, Show, ,MyWinTitle Gui, Cancel MsgBox, Check if the window exists Var := WinInView("Check", "MyWinTitle") If Var = -1 MsgBox, the window does not exist If Var = 0 MsgBox, the window exists and is hidden(due to GuiCancel) If Var = 1 MsgBox, the window exists and is showing(probly behind this MsgBox) MsgBox, Show the window WinInView("Change", "MyWinTitle","","","","1") MsgBox, Toggle the Window WinInView("Change", "MyWinTitle","","","","2") MsgBox, Toggle the window again! WinInView("Change", "MyWinTitle","","","","2") MsgBox, Hide the window WinInView("Change", "MyWinTitle","","","","0") ExitApp ;Function to return if window is hidden or not, change, or toggle state. ;; Param 1: Check/Change ; Check - Returns -1 if window does not exist ; Returns 0 if window is hidden ; Returns 1 If Window is showing ; Change - Returns -1 if Window does not exist ; Returns 0 if Windows final state is Hidden ; Returns 1 If Windows final state is Showing ;######################################################## ;; Param 6: Effect ; 0 (zero) - Hides window ; 1 (one) - Shows window ; 2 (two) - Toggles current state. WinInView(Action, WinTitle, WinText="", ExcludeTitle="", ExcludeText="", Effect="") { DHWState = %A_DetectHiddenWindows% If Action Not in Check,Change { Result = Error Return Result } DetectHiddenWindows, On IfWinNotExist, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% Result = -1 ;Else If Window Exists IfWinExist, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% { DetectHiddenWindows, Off WinGetPos, WinX,,,, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% ;If Window is hidden If WinX = Result = 0 ;If Window is showing Else Result = 1 } If Action = Change { ;Confirm Effect to take place, Return Error if None. If Effect Not between 0 and 2 { Result = Error Return Result } ;Show the window if it hidden If (Effect = 1) OR (Result = 0 AND Effect = 2) { WinShow, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% Result = 1 Return Result } ;Hide the window if it is shown If (Effect = 0) OR (Result = 1 AND Effect = 2) { WinHide, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText% Result = 0 Return Result } } DetectHiddenWindows, %DHWState% Return Result }