Sign in to follow this  
Followers 0
LarryK

Help with $GUI_EVENT_?

5 posts in this topic

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

Share this post


Link to post
Share on other sites

#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.

Share this post


Link to post
Share on other sites

Thank you Manadar and Alek! Alek, I used your second example and it works perfectly!

Larry

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0