Jump to content

A way to register if a window looses focus


Recommended Posts

For a small script I'm writing I want my window do be hidden if it looses focus. I don't want to have my computer checking every 20ms with If WinActive()... I know there is an easier way but I'm not sure what it is. Any ideas?

I was thinking using a GUIRegisterMsg() of some sort but I'm not sure what the parameters would be.

Edit: Found out that using WM_COMMAND it calls the function whenever the window is loose or gains focus, anybody know what the handle of the item that is triggering this? I thought it might be the GUI but it isn't. I'll post an example in a second...

Edited by Achilles
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

I was thinking something like:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("My Ownerdrawn Created Button", 300, 200)
;GUICtrlCreateInput ("", 10, 10)
;GUICtrlCreateInput ("", 10, 30)
GUIRegisterMsg($WM_KILLFOCUS, "KILL_FOCUS")
GUISetState()
While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func KILL_FOCUS($hWnd, $Msg, $wParam, $lParam)
    MsgBox (0, $hGUI, $hWnd & @CRLF & $Msg & @CRLF & $wParam & @CRLF & $lParam)
EndFunc

But as soon I added the input boxes, it stopped working... But its closer :P

Link to comment
Share on other sites

Achilles

Hi, try this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $Active = False

$hGUI = GUICreate("Test", 300, 200)

GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_ACTIVATE($hWnd, $Msg, $wParam, $lParam)
    $Active = Not $Active
    
    If $Active Then
        ConsoleWrite("-> Focused" & @LF)
    Else
        ConsoleWrite("-> Focus loosed" & @LF)
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc
Edited by rasim
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...