Sign in to follow this  
Followers 0

WinSnap - Automatic Window Alignment UDF


18 posts in this topic

Posted (edited)

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.

WinSnap.html

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:

Example 1:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "WinSnap.au3"
 
Global $style = BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX)
 
Global $GUI1 = GUICreate("GUI1", 200, 150, 100, 200, $style)
GUISetState(@SW_SHOW)
Global $GUI2 = GUICreate("GUI2", 200, 150, 370, 200, $style)
GUISetState(@SW_SHOW)
Global $GUI3 = GUICreate("GUI3", 200, 150, 100, 420, $style)
GUISetState(@SW_SHOW)
Global $GUI4 = GUICreate("GUI4", 200, 150, 370, 420, $style)
GUISetState(@SW_SHOW)
 
_WinSnap_Set($GUI1)
_WinSnap_Set($GUI2)
_WinSnap_Set($GUI3)
_WinSnap_Set($GUI4)
 
Do
Until GUIGetMsg() = -3

Example 2:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "WinSnap.au3"
Global $style = BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX)
Global $GUI1 = GUICreate("GUI1", 200, 150, 100, 200, $style)
Global $button1 = GUICtrlCreateButton('DisableAll', 60, 50, 80, 30)
GUISetState(@SW_SHOW)
Global $GUI2 = GUICreate("GUI2", 200, 150, 350, 200, $style)
Global $button2 = GUICtrlCreateButton('DisableAll', 60, 50, 80, 30)
GUISetState(@SW_SHOW)
_WinSnap_Set($GUI1)
_WinSnap_Set($GUI2)
Global $Msg
While 1
$Msg = GUIGetMsg()
Switch $Msg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $button1
   If GUICtrlRead($button1) = 'EnableAll' Then
    _WinSnap_SetStyle($GUI1, 3)
    GUICtrlSetData($button1, 'DisableAll')
   ElseIf GUICtrlRead($button1) = 'DisableAll' Then
    _WinSnap_SetStyle($GUI1, 0)
    GUICtrlSetData($button1, 'DeskOnly')
   ElseIf GUICtrlRead($button1) = 'DeskOnly' Then
    _WinSnap_SetStyle($GUI1, 1)
    GUICtrlSetData($button1, 'Moveonly')
   ElseIf GUICtrlRead($button1) = 'Moveonly' Then
    _WinSnap_SetStyle($GUI1, 2)
    GUICtrlSetData($button1, 'EnableAll')
   EndIf
  Case $button2
   If GUICtrlRead($button2) = 'EnableAll' Then
    _WinSnap_SetStyle($GUI2, 3)
    GUICtrlSetData($button2, 'DisableAll')
   ElseIf GUICtrlRead($button2) = 'DisableAll' Then
    _WinSnap_SetStyle($GUI2, 0)
    GUICtrlSetData($button2, 'DeskOnly')
   ElseIf GUICtrlRead($button2) = 'DeskOnly' Then
    _WinSnap_SetStyle($GUI2, 1)
    GUICtrlSetData($button2, 'Moveonly')
   ElseIf GUICtrlRead($button2) = 'Moveonly' Then
    _WinSnap_SetStyle($GUI2, 2)
    GUICtrlSetData($button2, 'EnableAll')
   EndIf
EndSwitch
WEnd

UDF:

#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

Share this post


Link to post
Share on other sites



Posted

Updated Posted Image

Share this post


Link to post
Share on other sites

Posted

Nice UDF :huh2:

Share this post


Link to post
Share on other sites

Posted

Cool work!

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

Br,

UEZ

Share this post


Link to post
Share on other sites

Posted

Nice UDF :huh2:

Thankyou!!

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

Nice work

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

Happy birthday, Beege!! :huh2:

Share this post


Link to post
Share on other sites

Posted

Happy birthday, Beege!! :huh2:

Thanks Maffe811!!! Posted Image

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

Absolutly exelent! Gonna excessively use it!

Share this post


Link to post
Share on other sites

Posted

Nice! Thankyou :graduated:

Share this post


Link to post
Share on other sites

Posted

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

Posted Image

Share this post


Link to post
Share on other sites

Posted (edited)

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

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