Jump to content

Drag GUI only in one direction


Leo1906
 Share

Recommended Posts

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
Link to comment
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

 

Link to comment
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?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...