Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

WinSnap - Automatic Window Alignment UDF

snap to alignment

  • Please log in to reply
17 replies to this topic

#1 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 30 May 2011 - 09:41 PM

Here is a UDF to easily apply that "snappy edge" effect to your GUI that you have probably seen on many programs. "Snappy" meaning anytime the boarder of your gui gets close to another windows boarder, or the desktop edges, your gui will automatically snap and align itself to that boarder. It is a very nice feature when it comes to aligning and resizeing your GUIs side by side.

One problem that I still have to hammer out is what Style you use for your GUI. If you choose to make the GUI non sizeable, it will still work but you'll see the edges will overlap a little bit. There is some invisible boarder there that isnt acounted for when I get the gui width and height. I need to look at Getsystemmetrics. Im pretty sure the answer is there.

Anyway plz take a look and tell me what you think. I love feed back or any new ideas. Thanks ;)

Updated 9/17/11: Automatic alignment to ALL visible windows now. Not just other Autoit windows. :huh2: Also removed _WinSnap_RegisterMsgs() as it is not nessasary. Windows Msgs are automatically registered on startup. See UDF header for more details.

Updated 5/31/11: Added new function _WinSnap_SetStyle() to configure what the window snaps to and to be able to enable/disable then snaps. Needed if you want to lock a window to another.

Attached File  WinSnap.html   148bytes   607 downloads
Previous Download:122
Note: The .html link is just to help me keep track of downloads. Open the .html file and a download dialog will display.

Examples:
Spoiler

UDF:
AutoIt         
#region Header ; #INDEX# ======================================================================================================================= ; Title .........: WinSnap ; AutoIt Version : 3.3.6.1 ; Language ......: English ; Description ...: Functions for making windows have "snap to" edges ; Author(s) .....: Beege ; Remarks........:  This UDF registers windows msgs WM_MOVING, WM_ENTERSIZEMOVE, WS_WM_SIZING. If any of these msgs ;     are registered in your script, your function must pass the msgs on to this UDF. Below are examples of the calls ; you will need to add if this is the case: ; ; Func WM_ENTERSIZEMOVE($hWndGUI, $MsgID, $wParam, $lParam) ; WS_WM_ENTERSIZEMOVE($hWndGUI, $MsgID, $wParam, $lParam) ; ;USER CODE; ; EndFunc   ;==>WM_SIZING; ; ; Func WM_MOVING($hWndGUI, $MsgID, $wParam, $lParam) ; WS_WM_MOVING($hWndGUI, $MsgID, $wParam, $lParam) ; ;USER CODE; ; EndFunc   ;==>WM_SIZING; ; ; Func WM_SIZING($hWndGUI, $MsgID, $wParam, $lParam) ; WS_WM_SIZING($hWndGUI, $MsgID, $wParam, $lParam) ; ;USER CODE; ; EndFunc   ;==>WM_SIZING; ; ; ===============================================================================================================================     ; #CURRENT# ===================================================================================================================== ; _WinSnap_Set ; _WinSnap_SetStyle ; ===============================================================================================================================   #include-once #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <WinAPI.au3> #endregion Header #region Global Varialbes ;~ Opt('MustDeclareVars', 1)   Global Enum $g_iHwnd, $g_iStyle Global $g_aSnapGUIs[1][2] = [[0, 0]] #cs $g_aSnapGUIs[$i][$g_iHwnd]  = Handle to window $g_aSnapGUIs[$i][$g_iStyle] = Style Flag #ce   Global $g_iMouseDistancetoX, $g_iMouseDistancetoY Global $g_iDesktopHeight Global $g_bMovingStarted = False Global $g_iMonitorTotal   Global Const $WS_WM_MOVING = 0x0216 Global Const $WS_WM_ENTERSIZEMOVE = 0x0231   GUIRegisterMsg($WS_WM_MOVING, "WS_WM_MOVING") GUIRegisterMsg($WS_WM_ENTERSIZEMOVE, 'WS_WM_ENTERSIZEMOVE') GUIRegisterMsg($WM_SIZING, 'WS_WM_SIZING')   #endregion Global Varialbes   #region Public functions ; #FUNCTION# ==================================================================================================== ; Name...........: _WinSnap_Set ; Description....: Sets window to have "snap to" edges ; Syntax.........: _WinSnap_Set($hGUI) ; Parameters.....: $hGUI - handle to window ; Return values..: Success -  1 ; Failure -  0 and sets @error ; Author.........: Beege ; Remarks........: None ; =============================================================================================================== Func _WinSnap_Set($hGUI)   $g_aSnapGUIs[0][0] += 1 ReDim $g_aSnapGUIs[$g_aSnapGUIs[0][0] + 1][2] $g_aSnapGUIs[$g_aSnapGUIs[0][0]][$g_iHwnd] = $hGUI $g_aSnapGUIs[$g_aSnapGUIs[0][0]][$g_iStyle] = 3   Local $tRectMoving = DllStructCreate($tagRECT) _WinAPI_SystemParametersInfo(0x0030, 0, DllStructGetPtr($tRectMoving), 0);SPI_GETWORKAREA If @error Then Return SetError(1, 0, 0) $g_iDesktopHeight = DllStructGetData($tRectMoving, 'Bottom')   $g_iMonitorTotal = _WinAPI_GetSystemMetrics(80);SM_CMONITORS If @error Then Return SetError(1, 0, 0)   Return 1   EndFunc   ;==>_WinSnap_Set   ; #FUNCTION# ==================================================================================================== ; Name...........: _WinSnap_SetStyle ; Description....: Sets what the window will snap to. Desktop edges or Window edges ; Syntax.........: _WinSnap_SetStyle($hGUI, $iFlag) ; Parameters.....: $hGUI - Handle to window to set style ; $iFlag - Style Value: ; | 0 = No Snap at all ; | 1 = Snap to Desktop Edges ; | 2 = Snap to Other Autoit Windows ; | 3 = Snap to all (Defualt) ; Return values..: Success - Returns the value of the previous setting ; Failure - 0 and set @error to 1 ; Author.........: Beege ; =============================================================================================================== Func _WinSnap_SetStyle($hGUI, $iFlag)   Local $iIndex = _GetIndex($hGUI) If Not $iIndex Then Return SetError(1, 0, 0)   Local $iLast = $g_aSnapGUIs[$iIndex][$g_iStyle] $g_aSnapGUIs[$iIndex][$g_iStyle] = $iFlag   Return $iLast   EndFunc   ;==>_WinSnap_SetStyle   #endregion Public functions   #region internel functions ; #FUNCTION# ==================================================================================================== ; Name...........: _GetIndex ; Description....: returns array index for handle ; Syntax.........: _GetIndex($hGUI) ; Parameters.....: $hGUI - handle to window ; Return values..: Success - array index for gui handle ; Failure - 0 ; Author.........: Beege ; =============================================================================================================== Func _GetIndex($hGUI) For $i = 1 To $g_aSnapGUIs[0][0] If $hGUI = $g_aSnapGUIs[$i][$g_iHwnd] Then Return $i Next Return 0 EndFunc   ;==>_GetIndex   ; #FUNCTION# ==================================================================================================== ; Name...........: WS_WM_ENTERSIZEMOVE ; Description....:  Called when window begins to move. ; Syntax.........: WS_WM_ENTERSIZEMOVE($hWndGUI, $MsgID, $wParam, $lParam) ; Return values..: None ; Author.........: Beege ; =============================================================================================================== Func WS_WM_ENTERSIZEMOVE($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam, $lParam   Local $pGUI1 = WinGetPos($hWndGUI) Local $aMousePos = MouseGetPos()   $g_bMovingStarted = False $g_iMouseDistancetoX = $aMousePos[0] - $pGUI1[0] $g_iMouseDistancetoY = $pGUI1[1] - $aMousePos[1]   EndFunc   ;==>WS_WM_ENTERSIZEMOVE   ; #FUNCTION# ==================================================================================================== ; Name...........: WS_WM_MOVING ; Description....: Called when a window is being moved ; Syntax.........: WS_WM_MOVING($hWndGUI, $MsgID, $wParam, $lParam) ; Return values..: None ; Author.........: Beege ; =============================================================================================================== Func WS_WM_MOVING($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam, $lParam   Static $iStartW, $iStartH   Local $iIndex = _GetIndex($hWndGUI) If Not $iIndex Then Return $GUI_RUNDEFMSG   Local $tRectMoving = DllStructCreate($tagRECT, $lParam)   If Not $g_bMovingStarted Then $g_bMovingStarted = True $iStartW = DllStructGetData($tRectMoving, 'Right') - DllStructGetData($tRectMoving, 'Left') $iStartH = DllStructGetData($tRectMoving, 'Bottom') - DllStructGetData($tRectMoving, 'Top') EndIf   ;If window is snaped we need to monitor how much the mouse has moved ;from is original drag point position on the title bar. Local $aMousePos = MouseGetPos() Local $iChangeinX = Abs($aMousePos[0] - (DllStructGetData($tRectMoving, 'Left') + $g_iMouseDistancetoX)) Local $iChangeinY = Abs((DllStructGetData($tRectMoving, 'Top') - $aMousePos[1]) - $g_iMouseDistancetoY)   Local $iTopMoving = DllStructGetData($tRectMoving, 'Top'), $iBottomMoving = DllStructGetData($tRectMoving, 'Bottom') Local $iLeftMoving = DllStructGetData($tRectMoving, 'Left'), $iRightMoving = DllStructGetData($tRectMoving, 'Right')   #region Check if near desktop edges ;Check if style includes snaping to desktop edges If BitAND($g_aSnapGUIs[$iIndex][$g_iStyle], 1) Then For $i = 1 To $g_iMonitorTotal If _IsClose($iRightMoving, (@DesktopWidth * $i)) Then DllStructSetData($tRectMoving, 'Right', (@DesktopWidth * $i)) DllStructSetData($tRectMoving, 'Left', DllStructGetData($tRectMoving, 'Right') - $iStartW) EndIf Next   For $i = 0 To $g_iMonitorTotal - 1 If _IsClose($iLeftMoving, (@DesktopWidth * $i)) Then DllStructSetData($tRectMoving, 'Left', (@DesktopWidth * $i)) DllStructSetData($tRectMoving, 'Right', DllStructGetData($tRectMoving, 'Left') + $iStartW) EndIf Next   If _IsClose($iTopMoving, 0) Then DllStructSetData($tRectMoving, 'Top', 0) DllStructSetData($tRectMoving, 'Bottom', DllStructGetData($tRectMoving, 'Top') + $iStartH) EndIf   If _IsClose($iBottomMoving, $g_iDesktopHeight) Then DllStructSetData($tRectMoving, 'Bottom', $g_iDesktopHeight) DllStructSetData($tRectMoving, 'Top', DllStructGetData($tRectMoving, 'Bottom') - $iStartH) EndIf   If _IsClose($iBottomMoving, @DesktopHeight) Then DllStructSetData($tRectMoving, 'Bottom', @DesktopHeight) DllStructSetData($tRectMoving, 'Top', DllStructGetData($tRectMoving, 'Bottom') - $iStartH) EndIf   ;Here we check if the mouse has moved from original drag point. if it has we unsnap the window If $iChangeinX > 20 Then DllStructSetData($tRectMoving, 'Left', $aMousePos[0] - $g_iMouseDistancetoX) DllStructSetData($tRectMoving, 'Right', DllStructGetData($tRectMoving, 'Left') + $iStartW) EndIf If $iChangeinY > 15 Then DllStructSetData($tRectMoving, 'Top', $aMousePos[1] + $g_iMouseDistancetoY) DllStructSetData($tRectMoving, 'Bottom', DllStructGetData($tRectMoving, 'Top') + $iStartH) EndIf   EndIf #endregion Check if near desktop edges   #region Check if window in near other Autoit Windows Local $aWinlist = WinList() ;Check if style of window includes other Autoit Windows If BitAND($g_aSnapGUIs[$iIndex][$g_iStyle], 2) Then   For $i = 1 To $aWinlist[0][0]   If $aWinlist[$i][0] = '' Or $aWinlist[$i][1] = $hWndGUI Or Not _IsVisible($aWinlist[$i][1]) Then ContinueLoop   Local $tRectNonMoving = _WinAPI_GetWindowRect($aWinlist[$i][1]) Local $iTopNonMoving = DllStructGetData($tRectNonMoving, 'Top'), $iBottomNonMoving = DllStructGetData($tRectNonMoving, 'Bottom') Local $iLeftNonMoving = DllStructGetData($tRectNonMoving, 'Left'), $iRightNonMoving = DllStructGetData($tRectNonMoving, 'Right')   If $iTopMoving <= ($iBottomNonMoving + 5) And ($iBottomMoving + 5) >= $iTopNonMoving Then ;Gui1Right to Gui2Right If _IsClose(DllStructGetData($tRectMoving, 'Right'), $iRightNonMoving) Then DllStructSetData($tRectMoving, 'Right', $iRightNonMoving) DllStructSetData($tRectMoving, 'Left', DllStructGetData($tRectMoving, 'Right') - $iStartW) EndIf   ;Gui1Left to Gui2left If _IsClose(DllStructGetData($tRectMoving, 'Left'), $iLeftNonMoving) Then DllStructSetData($tRectMoving, 'Left', $iLeftNonMoving) DllStructSetData($tRectMoving, 'Right', DllStructGetData($tRectMoving, 'Left') + $iStartW) EndIf   ;Gui1Left to Gui2Right If _IsClose(DllStructGetData($tRectMoving, 'Left'), $iRightNonMoving) Then DllStructSetData($tRectMoving, 'Left', $iRightNonMoving) DllStructSetData($tRectMoving, 'Right', DllStructGetData($tRectMoving, 'Left') + $iStartW) EndIf   ;Gui1Right to Gui2Left If _IsClose(DllStructGetData($tRectMoving, 'Right'), $iLeftNonMoving) Then DllStructSetData($tRectMoving, 'Right', $iLeftNonMoving) DllStructSetData($tRectMoving, 'Left', DllStructGetData($tRectMoving, 'Right') - $iStartW) EndIf EndIf   If ($iLeftMoving <= $iRightNonMoving + 5) And ($iRightMoving + 5 >= $iLeftNonMoving) Then ;gui1top to gui2top If _IsClose(DllStructGetData($tRectMoving, 'Top'), $iTopNonMoving) Then DllStructSetData($tRectMoving, 'Top', $iTopNonMoving) DllStructSetData($tRectMoving, 'Bottom', DllStructGetData($tRectMoving, 'Top') + $iStartH) EndIf   ;~  gui1top to gui2bottom If _IsClose(DllStructGetData($tRectMoving, 'Top'), $iBottomNonMoving) Then DllStructSetData($tRectMoving, 'Top', $iBottomNonMoving) DllStructSetData($tRectMoving, 'Bottom', DllStructGetData($tRectMoving, 'Top') + $iStartH) EndIf   ;gui1bottom to gui2bottom If _IsClose(DllStructGetData($tRectMoving, 'Bottom'), $iBottomNonMoving) Then DllStructSetData($tRectMoving, 'Bottom', $iBottomNonMoving) DllStructSetData($tRectMoving, 'Top', DllStructGetData($tRectMoving, 'Bottom') - $iStartH) EndIf   ;gui1bottom to gui2top If _IsClose(DllStructGetData($tRectMoving, 'Bottom'), $iTopNonMoving) Then DllStructSetData($tRectMoving, 'Bottom', $iTopNonMoving) DllStructSetData($tRectMoving, 'Top', DllStructGetData($tRectMoving, 'Bottom') - $iStartH) EndIf EndIf   ;Here we check if the mouse has moved from original drag point. if it has we unsnap the window If $iChangeinX > 20 Then DllStructSetData($tRectMoving, 'Left', $aMousePos[0] - $g_iMouseDistancetoX) DllStructSetData($tRectMoving, 'Right', DllStructGetData($tRectMoving, 'Left') + $iStartW) EndIf   If $iChangeinY > 15 Then DllStructSetData($tRectMoving, 'Top', $aMousePos[1] + $g_iMouseDistancetoY) DllStructSetData($tRectMoving, 'Bottom', DllStructGetData($tRectMoving, 'Top') + $iStartH) EndIf Next EndIf #endregion Check if window in near other Autoit Windows   Return $GUI_RUNDEFMSG   EndFunc   ;==>WS_WM_MOVING   ; #FUNCTION# ==================================================================================================== ; Name...........: WS_WM_SIZING ; Description....: Called when a window is being sized ; Syntax.........: WS_WM_SIZING($hWndGUI, $MsgID, $wParam, $lParam) ; Return values..: None ; Author.........: Beege ; =============================================================================================================== Func WS_WM_SIZING($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam, $lParam   If Not _GetIndex($hWndGUI) Then Return $GUI_RUNDEFMSG   Local $tRectMoving = DllStructCreate($tagRECT, $lParam) Local $iLeftMoving = DllStructGetData($tRectMoving, 'Left'), $iRightMoving = DllStructGetData($tRectMoving, 'Right') Local $iTopMoving = DllStructGetData($tRectMoving, 'Top'), $iBottomMoving = DllStructGetData($tRectMoving, 'Bottom')   #region check if resizing near desktop edge Switch $wParam Case 6; bottom edge If _IsClose($iBottomMoving, $g_iDesktopHeight) Then DllStructSetData($tRectMoving, 'Bottom', $g_iDesktopHeight) Case 7; bottom Left corner If _IsClose($iBottomMoving, $g_iDesktopHeight) Then DllStructSetData($tRectMoving, 'Bottom', $g_iDesktopHeight) If _IsClose($iLeftMoving, @DesktopWidth) Then DllStructSetData($tRectMoving, 'Left', @DesktopWidth) If _IsClose($iLeftMoving, 0) Then DllStructSetData($tRectMoving, 'Left', 0) Case 1; left If _IsClose($iLeftMoving, @DesktopWidth) Then DllStructSetData($tRectMoving, 'Left', @DesktopWidth) If _IsClose($iLeftMoving, 0) Then DllStructSetData($tRectMoving, 'Left', 0) Case 2; right If _IsClose($iRightMoving, @DesktopWidth) Then DllStructSetData($tRectMoving, 'Right', @DesktopWidth) ElseIf _IsClose($iRightMoving, @DesktopWidth * 2) Then DllStructSetData($tRectMoving, 'Right', (@DesktopWidth * 2)) EndIf Case 8; bottom right If _IsClose($iBottomMoving, $g_iDesktopHeight) Then DllStructSetData($tRectMoving, 'Bottom', $g_iDesktopHeight) If _IsClose($iRightMoving, @DesktopWidth) Then DllStructSetData($tRectMoving, 'Right', @DesktopWidth) ElseIf _IsClose($iRightMoving, @DesktopWidth * 2) Then DllStructSetData($tRectMoving, 'Right', (@DesktopWidth * 2)) EndIf Case 3; top If _IsClose($iTopMoving, 0) Then DllStructSetData($tRectMoving, 'Top', 0) Case 4; top left If _IsClose($iTopMoving, 0) Then DllStructSetData($tRectMoving, 'Top', 0) If _IsClose($iLeftMoving, @DesktopWidth) Then DllStructSetData($tRectMoving, 'Left', @DesktopWidth) Case 5; top right If _IsClose($iRightMoving, @DesktopWidth) Then DllStructSetData($tRectMoving, 'Right', @DesktopWidth) ElseIf _IsClose($iRightMoving, @DesktopWidth * 2) Then DllStructSetData($tRectMoving, 'Right', (@DesktopWidth * 2)) EndIf If _IsClose($iTopMoving, 0) Then DllStructSetData($tRectMoving, 'Top', 0) EndSwitch #endregion check if resizing near desktop edge   #region Check if resizing near other windows Local $aWinlist = WinList()   For $i = 1 To $aWinlist[0][0]   If $aWinlist[$i][0] = '' Or $aWinlist[$i][1] = $hWndGUI Or Not _IsVisible($aWinlist[$i][1]) Then ContinueLoop   Local $tRectNonMoving = _WinAPI_GetWindowRect($aWinlist[$i][1]) Local $iLeftNonMoving = DllStructGetData($tRectNonMoving, 'Left'), $iRightNonMoving = DllStructGetData($tRectNonMoving, 'Right') Local $iTopNonMoving = DllStructGetData($tRectNonMoving, 'Top'), $iBottomNonMoving = DllStructGetData($tRectNonMoving, 'Bottom')   Switch $wParam Case 6; bottom edge If ($iLeftMoving <= $iRightNonMoving + 5) And ($iRightMoving + 5 >= $iLeftNonMoving) Then If _IsClose(DllStructGetData($tRectMoving, 'Bottom'), $iBottomNonMoving) Then DllStructSetData($tRectMoving, 'Bottom', $iBottomNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Bottom'), $iTopNonMoving) Then DllStructSetData($tRectMoving, 'Bottom', $iTopNonMoving) EndIf Case 7; bottom Left corner If ($iLeftMoving <= $iRightNonMoving + 5) And ($iRightMoving + 5 >= $iLeftNonMoving) Then If _IsClose(DllStructGetData($tRectMoving, 'Left'), $iLeftNonMoving) Then DllStructSetData($tRectMoving, 'Left', $iLeftNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Left'), $iRightNonMoving) Then DllStructSetData($tRectMoving, 'Left', $iRightNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Bottom'), $iBottomNonMoving) Then DllStructSetData($tRectMoving, 'Bottom', $iBottomNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Bottom'), $iTopNonMoving) Then DllStructSetData($tRectMoving, 'Bottom', $iTopNonMoving) EndIf Case 1; left If $iTopMoving <= ($iBottomNonMoving + 5) And ($iBottomMoving + 5) >= $iTopNonMoving Then If _IsClose(DllStructGetData($tRectMoving, 'Left'), $iLeftNonMoving) Then DllStructSetData($tRectMoving, 'Left', $iLeftNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Left'), $iRightNonMoving) Then DllStructSetData($tRectMoving, 'Left', $iRightNonMoving) EndIf Case 2; right If $iTopMoving <= ($iBottomNonMoving + 5) And ($iBottomMoving + 5) >= $iTopNonMoving Then If _IsClose(DllStructGetData($tRectMoving, 'Right'), $iRightNonMoving) Then DllStructSetData($tRectMoving, 'Right', $iRightNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Right'), $iLeftNonMoving) Then DllStructSetData($tRectMoving, 'Right', $iLeftNonMoving) EndIf Case 8; bottom right If ($iLeftMoving <= $iRightNonMoving + 5) And ($iRightMoving + 5 >= $iLeftNonMoving) Then If _IsClose(DllStructGetData($tRectMoving, 'Bottom'), $iBottomNonMoving) Then DllStructSetData($tRectMoving, 'Bottom', $iBottomNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Bottom'), $iTopNonMoving) Then DllStructSetData($tRectMoving, 'Bottom', $iTopNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Right'), $iRightNonMoving) Then DllStructSetData($tRectMoving, 'Right', $iRightNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Right'), $iLeftNonMoving) Then DllStructSetData($tRectMoving, 'Right', $iLeftNonMoving) EndIf Case 3; top If ($iLeftMoving <= $iRightNonMoving + 5) And ($iRightMoving + 5 >= $iLeftNonMoving) Then If _IsClose(DllStructGetData($tRectMoving, 'Top'), $iBottomNonMoving) Then DllStructSetData($tRectMoving, 'Top', $iBottomNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Top'), $iTopNonMoving) Then DllStructSetData($tRectMoving, 'Top', $iTopNonMoving) EndIf Case 4; top left If ($iLeftMoving <= $iRightNonMoving + 5) And ($iRightMoving + 5 >= $iLeftNonMoving) Then If _IsClose(DllStructGetData($tRectMoving, 'Top'), $iBottomNonMoving) Then DllStructSetData($tRectMoving, 'Top', $iBottomNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Top'), $iTopNonMoving) Then DllStructSetData($tRectMoving, 'Top', $iTopNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Left'), $iLeftNonMoving) Then DllStructSetData($tRectMoving, 'Left', $iLeftNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Left'), $iRightNonMoving) Then DllStructSetData($tRectMoving, 'Left', $iRightNonMoving) If _IsClose($iLeftMoving, 0) Then DllStructSetData($tRectMoving, 'Left', 0) EndIf Case 5; top right If ($iLeftMoving <= $iRightNonMoving + 5) And ($iRightMoving + 5 >= $iLeftNonMoving) Then If _IsClose(DllStructGetData($tRectMoving, 'Top'), $iBottomNonMoving) Then DllStructSetData($tRectMoving, 'Top', $iBottomNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Top'), $iTopNonMoving) Then DllStructSetData($tRectMoving, 'Top', $iTopNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Right'), $iRightNonMoving) Then DllStructSetData($tRectMoving, 'Right', $iRightNonMoving) If _IsClose(DllStructGetData($tRectMoving, 'Right'), $iLeftNonMoving) Then DllStructSetData($tRectMoving, 'Right', $iLeftNonMoving) EndIf EndSwitch Next #endregion Check if resizing near other windows   Return $GUI_RUNDEFMSG   EndFunc   ;==>WS_WM_SIZING   ; #FUNCTION# ==================================================================================================== ; Name...........: _IsClose ; Description....: Tests if Position a is near Postion b ; Syntax.........: _IsClose($a, $b) ; Parameters.....: $a - Position 1 ; $b - Position 2 ; Return values..: True/False ; Author.........: Beege ; =============================================================================================================== Func _IsClose($a, $b) Return (Abs($a - $b) < 15) EndFunc   ;==>_IsClose #endregion internel functions   Func _IsVisible($handle) Return (BitAND(WinGetState($handle), 2) = 2) EndFunc   ;==>_IsVisible

Edited by Beege, 09 October 2011 - 12:22 AM.








#2 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 31 May 2011 - 08:57 PM

Updated Posted Image

#3 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,631 posts

Posted 31 May 2011 - 09:14 PM

Nice UDF :huh2:

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#4 UEZ

UEZ

    Never say never

  • MVPs
  • 5,039 posts

Posted 31 May 2011 - 09:15 PM

Cool work!

When snapping corners the distance is greater than when snapping sides. Is that intentional?

Br,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#5 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 31 May 2011 - 10:01 PM

Nice UDF :huh2:


Thankyou!!

#6 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 31 May 2011 - 10:05 PM

Cool work!

When snapping corners the distance is greater than when snapping sides. Is that intentional?

Br,
UEZ


Thankyou very much for the feedback and No it defiantly shouldn't. When you say corner and sides do you mean the desktop corners and sides or when your resizing a window using one of its corners or sides?

Edited by Beege, 31 May 2011 - 10:05 PM.


#7 monoscout999

monoscout999

    a member

  • Active Members
  • PipPipPipPipPipPip
  • 1,064 posts

Posted 31 May 2011 - 11:26 PM

Nice work

#8 UEZ

UEZ

    Never say never

  • MVPs
  • 5,039 posts

Posted 01 June 2011 - 07:55 AM

Thankyou very much for the feedback and No it defiantly shouldn't. When you say corner and sides do you mean the desktop corners and sides or when your resizing a window using one of its corners or sides?


If I start the Example.au3 and position the left upper corner of the 2nd window to the right bottom corner of the 1st window the distance of the edges between the two windows are too big regarding to the other snap behavior.

Br,
UEZ

Edited by UEZ, 01 June 2011 - 07:56 AM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#9 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 02 June 2011 - 08:25 PM

If I start the Example.au3 and position the left upper corner of the 2nd window to the right bottom corner of the 1st window the distance of the edges between the two windows are too big regarding to the other snap behavior.

Br,
UEZ


Ok I see what you mean. I'm pretty sure the windows are aligned with the correct distance, it just looks further because the windows show they have rounded corners, when in reality they have square corners that we cant see. I took a small snap shot to better explain.

Posted Image

If you look close at the green lines I drew you should see the horizontal borders line up perfectly, as well as the vertical ones do. If we could actually see the square corners they would be touching just right but we cant.. Hopefully were talking about the same thing. If not let me know. Thanks again for the feed back again. :huh2:

Edited by Beege, 02 June 2011 - 11:14 PM.


#10 UEZ

UEZ

    Never say never

  • MVPs
  • 5,039 posts

Posted 03 June 2011 - 10:47 AM

Yes, you are right, I didn't think about rounded corners of the windows. :huh2:

It would look nicer if the corner distance would be smaller...

Btw, happy birthday!

Br,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#11 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 03 June 2011 - 03:13 PM

Yes, you are right, I didn't think about rounded corners of the windows. :huh2:

It would look nicer if the corner distance would be smaller...

Btw, happy birthday!

Br,
UEZ



Ha thanks UEZ! First one this year. Your Awesome! Posted Image

#12 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 665 posts

Posted 03 June 2011 - 03:37 PM

Happy birthday, Beege!! :huh2:
Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#13 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 03 June 2011 - 05:07 PM

Happy birthday, Beege!! :huh2:


Thanks Maffe811!!! Posted Image

#14 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 17 September 2011 - 08:24 PM

Updated. Automatic alignment to ALL visible windows now. Not just other Autoit windows :graduated:

#15 matwachich

matwachich

    Polymath

  • Active Members
  • PipPipPipPip
  • 235 posts

Posted 01 October 2011 - 03:19 PM

Absolutly exelent! Gonna excessively use it!

#16 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 01 October 2011 - 03:30 PM

Nice! Thankyou :graduated:

#17 wakillon

wakillon

    Tiny Tools Coder

  • Active Members
  • PipPipPipPipPipPip
  • 2,918 posts

Posted 08 October 2011 - 08:40 AM

I have Aero Style with WindowBlinds and it give this : :graduated:

Posted Image

       AutoIt Version : 3.3.12.0 / Beta 3.3.13.19 SciTE 3.4.1 OS:WIN7/WIN8.1 CPU:X64 OS:X64


#18 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 09 October 2011 - 12:14 AM

I have Aero Style with WindowBlinds and it give this : :graduated:

This is something to do with that "one problem" I mentioned in post 1. The same thing happens when I change the style of the gui to be non resizable. Im guessing WindowsBlinds is changing the style of the window. Its snapping the window to the edge of the inner window and not the outer edge. Ill take another look at it. Maybe I can figure it out this time.

Edited by Beege, 09 October 2011 - 12:15 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users