#include-Once ; #INDEX# ======================================================================================================================= ; Title .........: SnapFix ; AutoIt Version : 3.3.14.1 ; UDF Version ...: 0.3 ; Status ........: Development ; Language ......: English ; Description ...: This UDF fixes an issue in Windows 10 Snap feature, that wrongly resizes a window when dragged way off-screen. ; The issue is apparent for non-resizable windows, when the Snap feature is turned OFF. ; The issue is discussed at the AutoIt forum, see link hereunder. ; Remarks .......: Only non-resizable GUI is impacted. If your AutoIt GUI is designed to be resizable (i.e. with thick border, ; docked controls, etc.) then you do not need to use this UDF. ; This UDF changes the default GUI resize mode. ; This UDF registers the window message WM_SIZE, so if your script registers the WM_SIZE message for its own ; purposes, then in your registered function, you must call the internal UDF function __SnapFix_WM_SIZE(). ; For example: ; Func MY_WM_SIZE($hWnd, $iMsg, $wParam, $lParam) ; __SnapFix_WM_SIZE($hWnd, $iMsg, $wParam, $lParam) ; ; your original function contents here ; EndFunc ; Also, for your function to be registered, you must call _SnapFix_Init() BEFORE you register your own function. ; Link ..........: https://www.autoitscript.com/forum/topic/177137-snapfix-udf-prevent-windows-10-from-molesting-your-non-resizable-gui/ ; https://www.autoitscript.com/forum/topic/176254-solution-revised-windows-10-clobbers-my-gui/ ; Dll ...........: ; Author(s) .....: orbs ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_SnapFix ;_SnapFix_Init ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SnapFix ; Description ...: Adds the given GUI to the list of GUI's to be processed for amending the Windows 10 Snap issue, or returns the ; said GUI properties in case it is already in the list. ; Syntax ........: _SnapFix($hGUI[, $bAdd=True]) ; Parameters ....: $hGUI - A handle to the AutoIt GUI. ; $bAdd - [optional] A variables that determines if the GUI is to be added to the list, or just be read from it. ; Return values .: An array of 3 elements containing the handle, width and height of the GUI. ; Author ........: orbs ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _SnapFix($hGUI, $bAdd = True) Local Enum $iGUI_Handle, $iGUI_Width, $iGUI_Height, $iGUI_ElementsCount ; ALERT: this line is declared in both _SnapFix() and __SnapFix_WM_SIZE() Local $iGUI Local $aWinPos Local $aResult[$iGUI_ElementsCount] Local Static $aGUI[1][$iGUI_ElementsCount] ; check to see if the given GUI is already in the list, if so => return its properties For $iGUI = 1 To $aGUI[0][0] If $hGUI = $aGUI[$iGUI][$iGUI_Handle] Then $aResult[$iGUI_Handle] = $aGUI[$iGUI][$iGUI_Handle] $aResult[$iGUI_Width] = $aGUI[$iGUI][$iGUI_Width] $aResult[$iGUI_Height] = $aGUI[$iGUI][$iGUI_Height] Return $aResult EndIf Next ; the given GUI is NOT already in the list. If $bAdd Then ; add it if needed ; - extend the list by one entry $aGUI[0][0] += 1 ReDim $aGUI[$aGUI[0][0] + 1][$iGUI_ElementsCount] ; - populate the new entry $iGUI = $aGUI[0][0] $aGUI[$iGUI][$iGUI_Handle] = $hGUI $aWinPos = WinGetPos($hGUI) $aGUI[$iGUI][$iGUI_Width] = $aWinPos[2] $aGUI[$iGUI][$iGUI_Height] = $aWinPos[3] ; - populate the return array $aResult[$iGUI_Handle] = $aGUI[$iGUI][$iGUI_Handle] $aResult[$iGUI_Width] = $aGUI[$iGUI][$iGUI_Width] $aResult[$iGUI_Height] = $aGUI[$iGUI][$iGUI_Height] Else ; do not add it, and it's not on the list => this GUI should NOT be processed => return -1 for the handle, the rest of the array is meaningless $iGUI = $aGUI[0][0] $aResult[$iGUI_Handle] = -1 $aResult[$iGUI_Width] = 0 $aResult[$iGUI_Height] = 0 EndIf ; return the array Return $aResult EndFunc ;==>_SnapFix ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SnapFix_Init ; Description ...: Initializes the SnapFix UDF: registers the WM_SIZE window message and changes the default GUI resize mode. ; Syntax ........: _SnapFix_Init() ; Parameters ....: None ; Return values .: None ; Author ........: orbs ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _SnapFix_Init() ; adapted from WindowsConstants.au3 Local Const $WM_SIZE = 0x05 ; adapted from GUIConstantsEx.au3 Local Const $GUI_DOCKLEFT = 0x0002 Local Const $GUI_DOCKTOP = 0x0020 Local Const $GUI_DOCKSIZE = 0x0300 ; init Opt('GUIResizeMode', BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) GUIRegisterMsg($WM_SIZE, '__SnapFix_WM_SIZE') EndFunc ;==>_SnapFix_Init ; #INTERNAL_USE_ONLY# =========================================================================================================== ;__SnapFix_WM_SIZE ;================================================================================================================================ ; #FUNCTION# ==================================================================================================================== ; Name ..........: __SnapFix_WM_SIZE ; Description ...: Resizes an AutoIt GUI impacted by the Windows 10 snap issue back to its normal size, and repels it back into ; the screen. ; Syntax ........: __SnapFix_WM_SIZE($hWnd, $iMsg, $wParam, $lParam) ; Parameters ....: $hWnd - A handle value. ; $iMsg - An integer value. ; $wParam - An unknown value. ; $lParam - An unknown value. ; Return values .: None ; Author ........: orbs ; Modified ......: ; Remarks .......: Although this function is internal, it may be used externally by the calling script - see the UDF header ; "Remarks" section for details. ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __SnapFix_WM_SIZE($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local Enum $iGUI_Handle, $iGUI_Width, $iGUI_Height, $iGUI_ElementsCount ; ALERT: this line is declared in both _SnapFix() and __SnapFix_WM_SIZE() #forceref $iGUI_ElementsCount Local $aGUI = _SnapFix($hWnd, False) If $aGUI[$iGUI_Handle] = $hWnd Then WinMove($hWnd, '', Default, 0, $aGUI[$iGUI_Width], $aGUI[$iGUI_Height]) EndFunc ;==>__SnapFix_WM_SIZE