Lazycat Posted April 6, 2006 Posted April 6, 2006 Very simple example, result of playing with new GUIRegisterMsg function. This is fasionable effect - form is snap to screen edges when moving. expandcollapse popup#include <GUIConstants.au3> Global Const $WM_WINDOWPOSCHANGING = 0x0046 Global Const $SPI_GETWORKAREA = 0x30 Global $nGap = 20, $nEdge = BitOR(1, 2, 4, 8); Left, Top, Right, Bottom $hGUI = GUICreate("Snapped window", 300, 200) GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING") GUISetState() While 1 $GUIMsg = GUIGetMsg() Switch $GUIMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam) #cs HWND hwnd; HWND hwndInsertAfter; int x; int y; int cx; int cy; UINT flags; #ce Local $stRect = DllStructCreate("int;int;int;int") Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam) DllCall("User32.dll", "int", "SystemParametersInfo", "int", $SPI_GETWORKAREA, "int", 0, "ptr", DllStructGetPtr($stRect), "int", 0) Local $nLeft = DllStructGetData($stRect, 1) Local $nTop = DllStructGetData($stRect, 2) Local $nRight = DllStructGetData($stRect, 3) - DllStructGetData($stWinPos, 5) Local $nBottom = DllStructGetData($stRect, 4) - DllStructGetData($stWinPos, 6) If BitAND($nEdge, 1) and Abs($nLeft - DllStructGetData($stWinPos, 3)) <= $nGap Then DllStructSetData($stWinPos, 3, $nLeft) If BitAND($nEdge, 2) and Abs($nTop - DllStructGetData($stWinPos, 4)) <= $nGap Then DllStructSetData($stWinPos, 4, $nTop) If BitAND($nEdge, 4) and Abs($nRight - DllStructGetData($stWinPos, 3)) <= $nGap Then DllStructSetData($stWinPos, 3, $nRight) If BitAND($nEdge, 8) and Abs($nBottom - DllStructGetData($stWinPos, 4)) <= $nGap Then DllStructSetData($stWinPos, 4, $nBottom) Return 0 EndFunc UEZ 1 Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s])
Moderators big_daddy Posted April 6, 2006 Moderators Posted April 6, 2006 Thats nice, I like it. Would it be possible to snap to another window?
Josbe Posted April 6, 2006 Posted April 6, 2006 @Lazycat: Great! Some weeks ago, I developed a similar function without DLLCall for a script that I will share here, but for any reason I had some problems with the desktop's corners...WINDOWPOSCHANGING do it better...Thanks. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta
Zedna Posted May 27, 2008 Posted May 27, 2008 Very COOL LazyCat! I discovered this after so many years ;-) Resources UDF ResourcesEx UDF AutoIt Forum Search
doodydota Posted October 8, 2008 Posted October 8, 2008 Very nice, thanks! And it so much less code than if I had tried to do this myself
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