Malkey Posted August 10, 2008 Share Posted August 10, 2008 What I was after was:-Snap enabled between the three created GUIs.No snapping to other desktop windows nor to desktop edges.Dragging snapped together GUIs as a unit. Ref postshttp://www.autoitscript.com/forum/index.ph...st&p=450377http://www.autoitscript.com/forum/index.ph...st&p=380176The jerky movement of dragging multiple GUIs suggests there is a better method.I could not get the mouse to capture multiple GUIs. This script is the result. expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Global Const $WM_EXITSIZEMOVE = 0x0232 Global Const $WM_ENTERSIZEMOVE = 0x0231 Global Const $SC_MOVE = 0xF010 ; from MenuConstants.au3 Global Const $SC_SIZE = 0xF000 ; from MenuConstants.au3 Global Const $ES_READONLY = 2048 ; from EditConstants.au3 Global $nRange = 25, $dragging = False Global $ahWnd[4][2] = [[3, 0],["GUI Stickable!", 0],["Some extra window", 0],["Extra window", 0]] Global $aCombined[4] Local $stopdrag = 0 GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING") GUIRegisterMsg($WM_ENTERSIZEMOVE, "WM_ENTERSIZEMOVE") $ahWnd[1][1] = GUICreate($ahWnd[1][0], 280, 150) GUISetState() $ahWnd[2][1] = GUICreate($ahWnd[2][0], 320, 180, 0, 0) GUISetState() $ahWnd[3][1] = GUICreate($ahWnd[3][0], 320, 180, 0, 220) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case - 7 ; $GUI_EVENT_PRIMARYDOWN If $stopdrag = 0 Then ;ignore this button down $wp3 = WinGetPos($ahWnd[3][0]) $wp2 = WinGetPos($ahWnd[2][0]) $wp1 = WinGetPos($ahWnd[1][0]) $mp1 = MouseGetPos() $dragging = True Else $stopdrag = 0 EndIf Case - 8 ; $GUI_EVENT_PRIMARYUP $dragging = False EndSwitch If $dragging And $stopdrag = 0 Then $mp = MouseGetPos() $hCW = WindowFromPoint($mp[0], $mp[1]) Switch $hCW Case $ahWnd[1][1] WinMove($ahWnd[1][0], "", $wp1[0] - $mp1[0] + $mp[0], $wp1[1] - $mp1[1] + $mp[1]) If CheckCombined($wp1, $wp2) Then WinMove($ahWnd[2][0], "", $wp2[0] - $mp1[0] + $mp[0], $wp2[1] - $mp1[1] + $mp[1]) If CheckCombined($wp2, $wp3) Then WinMove($ahWnd[3][0], "", $wp3[0] - $mp1[0] + $mp[0], $wp3[1] - $mp1[1] + $mp[1]) EndIf If CheckCombined($wp1, $wp3) Then WinMove($ahWnd[3][0], "", $wp3[0] - $mp1[0] + $mp[0], $wp3[1] - $mp1[1] + $mp[1]) If CheckCombined($wp3, $wp2) Then WinMove($ahWnd[2][0], "", $wp2[0] - $mp1[0] + $mp[0], $wp2[1] - $mp1[1] + $mp[1]) EndIf Case $ahWnd[2][1] WinMove($ahWnd[2][0], "", $wp2[0] - $mp1[0] + $mp[0], $wp2[1] - $mp1[1] + $mp[1]) If CheckCombined($wp2, $wp3) Then WinMove($ahWnd[3][0], "", $wp3[0] - $mp1[0] + $mp[0], $wp3[1] - $mp1[1] + $mp[1]) If CheckCombined($wp1, $wp3) Then WinMove($ahWnd[1][0], "", $wp1[0] - $mp1[0] + $mp[0], $wp1[1] - $mp1[1] + $mp[1]) EndIf If CheckCombined($wp2, $wp1) Then WinMove($ahWnd[1][0], "", $wp1[0] - $mp1[0] + $mp[0], $wp1[1] - $mp1[1] + $mp[1]) If CheckCombined($wp1, $wp3) Then WinMove($ahWnd[3][0], "", $wp3[0] - $mp1[0] + $mp[0], $wp3[1] - $mp1[1] + $mp[1]) EndIf Case $ahWnd[3][1] WinMove($ahWnd[3][0], "", $wp3[0] - $mp1[0] + $mp[0], $wp3[1] - $mp1[1] + $mp[1]) If CheckCombined($wp3, $wp2) Then WinMove($ahWnd[2][0], "", $wp2[0] - $mp1[0] + $mp[0], $wp2[1] - $mp1[1] + $mp[1]) If CheckCombined($wp2, $wp1) Then WinMove($ahWnd[1][0], "", $wp1[0] - $mp1[0] + $mp[0], $wp1[1] - $mp1[1] + $mp[1]) EndIf If CheckCombined($wp3, $wp1) Then WinMove($ahWnd[1][0], "", $wp1[0] - $mp1[0] + $mp[0], $wp1[1] - $mp1[1] + $mp[1]) If CheckCombined($wp2, $wp1) Then WinMove($ahWnd[2][0], "", $wp2[0] - $mp1[0] + $mp[0], $wp2[1] - $mp1[1] + $mp[1]) EndIf EndSwitch if GUIGetMsg() = -8 then $dragging = False ; $GUI_EVENT_PRIMARYUP Else $wp3 = WinGetPos($ahWnd[3][0]) $wp2 = WinGetPos($ahWnd[2][0]) $wp1 = WinGetPos($ahWnd[1][0]) $mp1 = MouseGetPos() EndIf WEnd Func CheckCombined(ByRef $wpa,ByRef $wpb) Local $bJoined = False If ($wpa[0] + $wpa[2]) = $wpb[0] And Abs($wpa[1] - $wpb[1]) < $wpa[3] And Abs($wpa[1] - $wpb[1]) < $wpb[3] Then $bJoined = true If ($wpb[0] + $wpb[2]) = $wpa[0] And Abs($wpa[1] - $wpb[1]) < $wpa[3] And Abs($wpa[1] - $wpb[1]) < $wpb[3] Then $bJoined = true If ($wpb[1] + $wpb[3]) = $wpa[1] And Abs($wpa[0] - $wpb[0]) < $wpa[2] And Abs($wpa[0] - $wpb[0]) < $wpb[2] Then $bJoined = true If ($wpa[1] + $wpa[3]) = $wpb[1] And Abs($wpa[0] - $wpb[0]) < $wpa[2] And Abs($wpa[0] - $wpb[0]) < $wpb[2] Then $bJoined = true Return $bJoined EndFunc ;==>CheckCombined Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam) Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam) Local $nLeft = DllStructGetData($stWinPos, 3) Local $nTop = DllStructGetData($stWinPos, 4) Local $aCurWinPos = WinGetPos($hWnd) ;Local $ahWnd = WinList() For $i = 1 To UBound($ahWnd) - 1 $aSideWinPos = WinGetPos($ahWnd[$i][1]) If UBound($aSideWinPos) < 3 Then ContinueLoop Local $XPoint = $aSideWinPos[0] + 1 Local $YPoint = $aSideWinPos[1] + 1 If $XPoint < 0 Then $XPoint = 1 If $YPoint < 0 Then $YPoint = 1 ;Left If Abs(($aSideWinPos[0] + $aSideWinPos[2]) - $nLeft) <= $nRange And _ WindowFromPoint($XPoint, $YPoint) = $ahWnd[$i][1] Then _ DllStructSetData($stWinPos, 3, $aSideWinPos[0] + $aSideWinPos[2]) ;Right If Abs($nLeft + $aCurWinPos[2] - $aSideWinPos[0]) <= $nRange And _ WindowFromPoint($XPoint, $YPoint) = $ahWnd[$i][1] Then _ DllStructSetData($stWinPos, 3, $aSideWinPos[0] - $aCurWinPos[2]) ;Top If Abs(($aSideWinPos[1] + $aSideWinPos[3]) - $nTop) <= $nRange And _ WindowFromPoint($XPoint, $YPoint) = $ahWnd[$i][1] Then _ DllStructSetData($stWinPos, 4, $aSideWinPos[1] + $aSideWinPos[3]) ;Bottom If Abs($nTop + $aCurWinPos[3] - $aSideWinPos[1]) <= $nRange And _ WindowFromPoint($XPoint, $YPoint) = $ahWnd[$i][1] Then _ DllStructSetData($stWinPos, 4, $aSideWinPos[1] - $aCurWinPos[3]) Next Sleep(10) Return 0 EndFunc ;==>WM_WINDOWPOSCHANGING Func wm_entersizemove() $stopdrag = 1;or else might not stop dragging EndFunc ;==>wm_entersizemove Func WindowFromPoint($XPoint, $YPoint) Local $aResult = DllCall("User32.dll", "hwnd", "WindowFromPoint", "int", $XPoint, "int", $YPoint) Return $aResult[0] EndFunc ;==>WindowFromPointTo un-snap, drag with GUI title bar. 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