LarryK Posted April 12, 2007 Posted April 12, 2007 I am a real noob here, but I have searched for something like this and can't find it... I have a GUI that I would like to close when it loses focus. There is not a GUI constant for this in GUIConstantsEx.au3, so is there a way to capture this event? For example, it would look something like: If $msg = $GUI_EVENT_LOSEFOCUS Then ExitLoop Thank you for your help! Larry
jvanegmond Posted April 12, 2007 Posted April 12, 2007 #include <GUIConstants.au3> $GUI = GUICreate("Close if focus is lost", 400, 400) GUISetState() While 1 If Not WinActive($GUI) Then Exit EndIf $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd github.com/jvanegmond
LarryK Posted April 12, 2007 Author Posted April 12, 2007 #include <GUIConstants.au3> $GUI = GUICreate("Close if focus is lost", 400, 400) GUISetState() While 1 If Not WinActive($GUI) Then Exit EndIf $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd This works "sort of". Because it's not a windows event, you have to click another window and hold it long enough to have the GUI loop one more time for it to tell that it's no longer active. If you don't hold the click long-enough, my GUI just takes the focus again and keeps on going.
Alek Posted April 12, 2007 Posted April 12, 2007 (edited) maybe #include <GUIConstants.au3> $GUI = GUICreate("Close if focus is lost", 400, 400) GUISetState() do $nMsg = GUIGetMsg() until $nMsg = $GUI_EVENT_CLOSE or not WinActive($GUI) exit Edited April 12, 2007 by Alek [font="Impact"]Never fear, I is here.[/font]
LarryK Posted April 12, 2007 Author Posted April 12, 2007 Thank you Manadar and Alek! Alek, I used your second example and it works perfectly! Larry
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now