ryantollefson Posted March 17, 2008 Share Posted March 17, 2008 Is there a way to see when a window has changed position? For example, if I have a calculator window open, and I want my script to know if I have moved the calculator (moving it with the mouse, not moving it with the script)? Ideally I would also like to be able to see when the program has been minimized as well. The other thing I would like for this to do is to be similar to OnEvent, I don't want to be constantly polling & comparing the window position if I can avoid it. I was looking at the WM_WINDOWPOSCHANGED and the winapi, but I don't know how use it for this (or if it can be done). Link to comment Share on other sites More sharing options...
Dampe Posted March 17, 2008 Share Posted March 17, 2008 (edited) I guess you could do something like this: While 2 $pos = WinGetPos ("", "") While 1 $pos2 = WinGetPos ("", "") If $pos[0] <> $pos2[0] Then ;window has moved TrayTip ("Window has moved!", "The window has moved!", 1) ExitLoop ElseIf $pos[1] <> $pos2[1] Then ;window has moved TrayTip ("Window has moved!", "The window has moved!", 1) ExitLoop Else ;Nothing EndIf WEnd WEnd Win_Api would work better though. Edited March 17, 2008 by Dampe Link to comment Share on other sites More sharing options...
ryantollefson Posted March 17, 2008 Author Share Posted March 17, 2008 Win_Api would work better though.That's what I was thinking too, just wasn't sure how to use it for this. Link to comment Share on other sites More sharing options...
FreeFry Posted March 17, 2008 Share Posted March 17, 2008 (edited) This is how you could use it: expandcollapse popup#include <GUIConstants.au3> $Form1 = GUICreate("Form1", 633, 447, 193, 115) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_WINDOWPOSCHANGED, "_WinPosChanged") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ;~ typedef struct { ;~ HWND hwnd; ;~ HWND hwndInsertAfter; ;~ int x; ;~ int y; ;~ int cx; ;~ int cy; ;~ UINT flags; ;~ } WINDOWPOS; Func _WinPosChanged($hWndGUI, $MsgID, $WParam, $LParam) Local $winpos_Struct = DllStructCreate("hwnd hwnd;hwnd hwndInsertAfter;int x;int y;int cx;int cy;uint flags", $LParam) If @error Then _Exit("Error while creating the struct") ConsoleWrite("Position Changed to:" & @LF) ConsoleWrite("X: " & DllStructGetData($winpos_Struct, "x") & @LF) ConsoleWrite("Y: " & DllStructGetData($winpos_Struct, "y") & @LF) EndFunc Func _Exit($s_Msg) MsgBox(0, "Error", $s_Msg) Exit EndFuncoÝ÷ ØúènW¦ËajÒ¢}ý¶IèÂ0¶h×è®az¼"Ú0°ýz-²êÞÝý²,²&å{iÙe~)^jÈ(!¶·ªº*Þj(±ßÛ!زv( xÛaȬÂ!ƦzêpØZºÚ"µÍÚ[ÛYH ÑÕRPÛÛÝ[Ë]LÉÝÂÛØ[ÛÛÝ ÌÍÕÒÐÐSÓÐÈH ÌÍÑÜLHHÕRPÜX]J ][ÝÑÜLI][ÝË ÌË ËNLËLMJBÌÍÕXYQHØ[ ][ÝÚÙ[Ì ][ÝË ][ÝÙÛÜ ][ÝË ][ÝÑÙ]Ý[XYY ][ÝÊBÌÍÐØ[XÚÈHØ[XÚÔYÚÝ ][Ý×ÐØ[ÛØÉ][ÝË ][ÝÛÛÉ][ÝË ][ÝÚ[ÝÜ[NÛ[I][ÝÊBÌÍÒÓÒÈHØ[ ][ÝÝÙÌ ][ÝË ][ÝÚÛ ][ÝË ][ÝÔÙ]Ú[ÝÜÒÛÚÑ^ ][ÝË ][ÝÚ[ ][ÝË ÌÍÕÒÐÐSÓÐË ][ÝÜ][ÝËØ[XÚÑÙ] ÌÍÐØ[XÚÊK ][ÝÚÛ ][ÝË ][ÝÙÛÜ ][ÝË ÌÍÕXYQÌJBÕRTÙ]Ý]JÕ×ÔÒÕÊBÚ[HBIÌÍÛÙÈHÕRQÙ]ÙÊ BTÝÚ]Ú ÌÍÛÙÂBPØÙH ÌÍÑÕRWÑUSÐÓÔÑBBBQ^]Q[ÝÚ]ÚÑ[[ÈÐØ[ÛØÊ ÌÍÛÛÙK ÌÍÝÔ[K ÌÍÛ[JBBRY ÌÍÛÛÙH È[BSØØ[ ÌÍÚWÔ]HØ[ ][ÝÝÙÌ ][ÝË ][ÝÛÛÉ][ÝË ][ÝÐØ[^ÛÚÑ^ ][ÝË ][ÝÚÛ ][ÝË ÌÍÒÓÒÖÌK ][ÝÚ[ ][ÝË ÌÍÛÛÙK ][ÝÝÜ[I][ÝË ÌÍÝÔ[K ][ÝÛ[I][ÝË ÌÍÛ[JBBT] ÌÍÚWÔ]ÌBQ[YBSØØ[ ÌÍÐÕÔÕPÕHÝXÝÜX]J ][ÝÛÛÈ[NÛÛÈÔ[NÝZ[YÜØYÙNÚÛÛ ][ÝË ÌÍÛ[JBRYÜ[Ñ^] ][ÝÑÜÚ[HÜX][ÈÝXÝ ][ÝÈ [ÈÜBBRYÝXÝÙ]]J ÌÍÐÕÔÕPÕ ][ÝÓYÜØYÙI][ÝÊH ÉÝÈ ÌÍÕÓWÕÒSÕÔÔÐÒSÑQ[BIÌÍÐÕÔÕPÕHBT]Q[YBSØØ[ ÌÍÝÚ[Ü×ÔÝXÝHÝXÝÜX]J ][ÝÚÛÛÚÛÛ[ÙYÚ[Ú[NÚ[ÞÚ[ÞNÝZ[YÜÉ][ÝËÝXÝÙ]]J ÌÍÐÕÔÕPÕ ][ÝÛ[I][ÝÊJBBPÛÛÛÛUÜ]J ][ÝÔÜÚ][ÛÚ[ÙYÎ][ÝÈ [ÈBÛÛÛÛUÜ]J ][ÝÖ ][ÝÈ [ÈÝXÝÙ]]J ÌÍÝÚ[Ü×ÔÝXÝ ][ÝÞ ][ÝÊH [ÈBÛÛÛÛUÜ]J ][ÝÖN ][ÝÈ [ÈÝXÝÙ]]J ÌÍÝÚ[Ü×ÔÝXÝ ][ÝÞI][ÝÊH [ÈBBIÌÍÐÕÔÕPÕHIÌÍÝÚ[Ü×ÔÝXÝHB[[Â[ÈÑ^] ÌÍÜ×ÓÙÊBBPÛÛÛÛUÜ]J ][ÝÑÜ ][ÝÈ [È ÌÍÜ×ÓÙÈ [ÈBQ^]B[[Â[ÈÛ]]Ò]^] BBQØ[ ][ÝÝÙÌ ][ÝË ][ÝÚÛ ][ÝË ][ÝÕ[ÛÚÕÚ[ÝÜÒÛÚÑ^ ][ÝË ][ÝÚÛ ][ÝË ÌÍÒÓÒÖÌJBQØ[XÚÑYJ ÌÍÐØ[XÚÊBB[[ This is probably the way to go towards hooking into another window, but I'm afraid you still need to use a DLL for this type of hook, as of now it seems it will only work on your own applicaiton. :/ Edited March 17, 2008 by FreeFry Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted July 22, 2008 Share Posted July 22, 2008 Thanks FreeFry. muttley Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
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