Leo1906 Posted September 11, 2016 Share Posted September 11, 2016 (edited) Hello Guys I'm having a question right here. Is it possible to set an option that your GUI for example can only be dragged to it's right hand side? Or generally only on the x axis? I think it could be achieveable when using the Mouse Repel function I encountered during my research, but before trying to implement this function I would like to know if there is a shorter way. Maybe due to some WinAPI calls or something like that? Thanks in advance for your help Edit: I think the function _MouseTrap would be better than repel. I think there should be no problem calling this function while the GUI is beeing dragged and afterwards release the _MouseTrap aggain. But still: if there a more simple way to do this, please let me know Edited September 11, 2016 by Leo1906 Link to comment Share on other sites More sharing options...
InunoTaishou Posted September 11, 2016 Share Posted September 11, 2016 #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> Local $hGUI = GUICreate("GUI") GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_WINDOWPOSCHANGING, 'WM_WINDOWPOSCHANGING') While (True) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Local $aWinGetPos = WinGetPos($hWnd) If @error Then Return $GUI_RUNDEFMSG Local $tWindowPos = DllStructCreate($tagWINDOWPOS, $lParam) ;~ DllStructSetData($tWindowPos, 'X', $aWinGetPos[0]) ; Lock the X position DllStructSetData($tWindowPos, 'Y', $aWinGetPos[1]) ; Lock the Y position Return $GUI_RUNDEFMSG EndFunc ;==>WM_WINDOWPOSCHANGING Leo1906 1 Link to comment Share on other sites More sharing options...
Leo1906 Posted September 11, 2016 Author Share Posted September 11, 2016 3 minutes ago, InunoTaishou said: #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> Local $hGUI = GUICreate("GUI") GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_WINDOWPOSCHANGING, 'WM_WINDOWPOSCHANGING') While (True) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Local $aWinGetPos = WinGetPos($hWnd) If @error Then Return $GUI_RUNDEFMSG Local $tWindowPos = DllStructCreate($tagWINDOWPOS, $lParam) ;~ DllStructSetData($tWindowPos, 'X', $aWinGetPos[0]) ; Lock the X position DllStructSetData($tWindowPos, 'Y', $aWinGetPos[1]) ; Lock the Y position Return $GUI_RUNDEFMSG EndFunc ;==>WM_WINDOWPOSCHANGING That's really cool. Definitely something I couldn't have come up with on my own .. One last thing: Is it possible to delimit the range a bit more? Like if I want my GUI to be only dragable to the right, till the monitor ends? With this function you can only delimit the drag to x and y and not an x-range, right? Link to comment Share on other sites More sharing options...
InunoTaishou Posted September 11, 2016 Share Posted September 11, 2016 Compare the X position from the DLLStructGetData($tWindowPos, "X") and the $aWinGetPos[0]. If the new X is greater than the $aWinGetPos[0] then allow the move, if the new X is less than the $aWinGetPos[0] then set the X position using the commented out line. Leo1906 1 Link to comment Share on other sites More sharing options...
Leo1906 Posted September 11, 2016 Author Share Posted September 11, 2016 Yeah you're right Thanks for helping me think .. could have thought about that myself .. Now it all works perfectly! Thanks for your help 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