rich2323 Posted April 28, 2010 Share Posted April 28, 2010 (edited) What is the simplest way to limit a GuiWindow from being dragged off the screen(i still want the ability to drag), or limit it to be only dragged in a limited area on the screen. Here is my sample script. Local $msg GUICreate("IT DEPARTMENT - Restart Required", 415, 145, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_TOPMOST ) ; Creates GUI Window ;GUICreate("My GUI") ; will create a dialog box that when displayed is centered GUISetState(@SW_SHOW) ; will display an empty dialog box ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Any help would be greatly appreciated. Thanks, Rich Edited April 28, 2010 by rich2323 Link to comment Share on other sites More sharing options...
l3ill Posted April 28, 2010 Share Posted April 28, 2010 Maybe _MouseTrap ? My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 28, 2010 Moderators Share Posted April 28, 2010 (edited) rich2323,This is a way to limit the coords within the WM_MOVE message function - but I am sure there must be a better way than using WinMove: There is - see below! #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $iX_Min = 100, $iX_Max = @DesktopWidth - 100, $iY_Min = 100, $iY_Max = @DesktopHeight - 100 $hGUI = GUICreate("Test", 500, 500) GUISetState() GUIRegisterMsg($WM_MOVE, "WM_MOVE") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_MOVE($hWnd, $iMsg, $iwParam, $ilParam) if ($hWnd = $hGUI) then $aWinPos = WinGetPos($hWnd) If $aWinPos[0] < $iX_Min Then WinMove($hGUI, "", $iX_Min, Default) If $aWinPos[1] < $iY_Min Then WinMove($hGUI, "", Default, $iY_Min) If $aWinPos[0] + $aWinPos[2] > $iX_Max Then WinMove($hGUI, "", $iX_Max - $aWinPos[2], Default) If $aWinPos[1] + $aWinPos[3] > $iY_Max Then WinMove($hGUI, "", Default, $iY_Max - $aWinPos[3]) EndIf EndFuncI will keep looking. M23Edit:I was looking in the wrong place - we needed to intercept WM_WINDOWPOSCHANGING: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Global $iX_Min = 100, $iX_Max = @DesktopWidth - 600, $iY_Min = 100, $iY_Max = @DesktopHeight - 600 $hGUI = GUICreate("Test", 500, 500) GUISetState() GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam) Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam) Local $iLeft = DllStructGetData($stWinPos, 3) Local $iTop = DllStructGetData($stWinPos, 4) Local $iWidth = DllStructGetData($stWinPos, 5) Local $iHeight = DllStructGetData($stWinPos, 6) If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min) If $iTop < $iY_Min Then DllStructSetData($stWinPos, 4, $iY_Min) If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max) If $iTop > $iY_Max Then DllStructSetData($stWinPos, 4, $iY_Max) EndFuncI hope that suffices! M23 Edited April 28, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rich2323 Posted April 28, 2010 Author Share Posted April 28, 2010 Perfect !! Thank you! 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