Sign in to follow this  
Followers 0
Leo1906

Drag GUI only in one direction

5 posts in this topic

#1 ·  Posted (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 by Leo1906

Share this post


Link to post
Share on other sites



#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

 

1 person likes this

Share this post


Link to post
Share on other sites
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 .. :blink:

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?

Share this post


Link to post
Share on other sites

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.

1 person likes this

Share this post


Link to post
Share on other sites

Yeah you're right :D
Thanks for helping me think .. could have thought about that myself .. :>

 

Now it all works perfectly! Thanks for your help :)

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