Sign in to follow this  
Followers 0

Fire event on window creation/resize/move/close

7 posts in this topic

Posted (edited)

How would I go about waiting for interaction of a window on the desktop and targeting that window?

I'm making a window-organizing app (which I'll share after it's complete) and want to watch for when a window is resized/moved on the desktop.

Edited by mechaflash213
Jardz likes this

Share this post


Link to post
Share on other sites



Posted

I would use the GUIRegisterMsg function and look for the $WM_SYSCOMMAND actions. In my signature is a link to a demo script that I created that shows you the different messages sent by the GUI when you interact with it. The move action isn't listed, but the parameter to look for is WParam = 0xF012 for clicking on the title bar of a gui.

Share this post


Link to post
Share on other sites

Posted

WM_MOVE and WM_RESIZE may help with GUIRegisterMsg

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks Brew. This will work out nicely.

EDIT: I'll look into it Phoenix thx.

Edited by mechaflash213

Share this post


Link to post
Share on other sites

Posted (edited)

Did a miniscule test on when a new window is created. The initial _ArrayDisplay() fires the event, however opening up application windows/system windows (New firefox instance and new My Documents instance) doesn't fire it.

I'm thinking GUIRegisterMsg() is only for the actual GUI created by AutoIt and not any window?

EDIT: Removed $iWinCount and added it to the 0 index on $ahWinList

EDIT2: Added _WinOrg_UnRegisterWindow() function to show it fires when you close the _ArrayDisplay()

#include <Array.au3>

;~ HotKeySet("^!e", "_IncludeExclude")

GUIRegisterMsg(0x0001, "_WinOrg_RegisterWindow") ; If Window is Created
GUIRegisterMsg(0x0002, "_WinOrg_UnRegisterWindow") ; If Window is Destroyed
;~ GUIRegisterMsg(0x0003, "_WinOrg_WindowCheck") ; If Window Moves
;~ GUIRegisterMsg(0x0005, "_WinOrg_WindowCheck") ; If Window is Resized
;~ GUIRegisterMsg(0x0047, "_WinOrg_WindowCheck") ; If Window Position Changes

; Global $ahWinList Defined in _WinOrg_Initialize()

_WinOrg_Initialize()
_ArrayDisplay($ahWinList)
_ArrayDisplay($ahWinList)

While 1
    Sleep(100)
WEnd

Func _WinOrg_Initialize()
    $avWinListTemp = WinList()
    Global $ahWinList[$avWinListTemp[0][0]]
    $x = 0
    For $i = 1 To $avWinListTemp[0][0]
        If $avWinListTemp[$i][0] <> "" And _WinOrg_IsVisible($avWinListTemp[$i][1]) Then
            $x+=1
            $ahWinList[$x] = $avWinListTemp[$i][1]
        EndIf
    Next
    $ahWinList[0] = $x
    ReDim $ahWinList[$x + 1]
EndFunc

    Func _WinOrg_IsVisible($handle)
        If BitAND(WinGetState($handle), 2) Then
            Return 1
        Else
            Return 0
        EndIf
    EndFunc

Func _WinOrg_RegisterWindow($hWndGUI, $MsgID)
    msgbox(0,"","REGISTERED WINDOW WITH HANDLE: " & $hWndGUI)
EndFunc

Func _WinOrg_UnRegisterWindow($hWndGUI, $MsgID)
    msgbox(0,"","UNREGISTERED WINDOW WITH HANDLE: " & $hWndGUI)
EndFunc
Edited by mechaflash213

Share this post


Link to post
Share on other sites

Posted (edited)

Was doing some research... I believe the only way to accomplish this is to hook in WH_GETMESSAGE. However, hooks, dlls and the like are still above and beyond my knowledge of use. So at this time, I'll just use a loop gathering window handles and running checks against it. It may or may not be slower than the hook method, as hooking WH_GETMESSAGE does increase processing time, but the code would be a bit cleaner and easier to adjust/expand upon via the hook method.

If I get around to implementing it via the hook method, I'll update the OP.

Edited by mechaflash213

Share this post


Link to post
Share on other sites

Posted

How would I go about waiting for interaction of a window on the desktop and targeting that window?

I'm making a window-organizing app (which I'll share after it's complete) and want to watch for when a window is resized/moved on the desktop.

_WinAPI_SetWinEventHook($EVENT_SYSTEM_MOVESIZESTART, $EVENT_SYSTEM_MOVESIZEEND, $pEventProc)

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