Jump to content
Sign in to follow this  
Vadersapien

Button to drag window.

Recommended Posts

Vadersapien

Hello,

I would like to know how to create a button that will allow the user to drag the GUI around.


Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.

Share this post


Link to post
Share on other sites
Mat

You can do it with a button but its not pretty...

A better solution is to use a label. (And try to make it look like a button)

#Include<GUIConstantsEx.au3>
#Include<WindowsConstants.au3>
#Include<StaticConstants.au3>

$hGUI = GUICreate ("testing", 400, 300)

$hLabel = GUICtrlCreateLabel ("Drag ME!!", 20, 20, 80, 30, BitOR ($WS_SIZEBOX, $SS_CENTER), $GUI_WS_EX_PARENTDRAG)

GUISetState ()

While 1
   Switch GUIGetMsg ()
      Case -3
         Exit
   EndSwitch
WEnd

If you really must use a button then this is one possible workaround

#Include<Misc.au3>

$hGUI = GUICreate ("testing", 400, 300)

$hButton = GUICtrlCreateButton ("Drag ME!!", 20, 20, 80, 30)

GUISetState ()

While 1
   Switch GUIGetMsg ()
      Case -3
         Exit
      Case Else
         $aFirst = GUIGetCursorInfo ()
         If Not IsArray ($aFirst) Then ContinueLoop
         If $aFirst[2] = 0 Then ContinueLoop
         If $aFirst[4] <> $hButton Then ContinueLoop
         $aFirst[0] += 3
         $aFirst[1] += 24

         While _IsPressed (01)
            $aPos = MouseGetPos ()
            WinMove ($hGUI, "", $aPos[0] - $aFirst[0], $aPos[1] - $aFirst[1])
         WEnd
   EndSwitch
WEnd

Mat

Edit: Updated second code.

Edited by Mat

Share this post


Link to post
Share on other sites
PsaltyDS

Another way (doesn't require holding the mouse down), just for fun:

#include <GUIConstantsEx.au3>

Global $hGUI, $idButton, $aMPos
$hGUI = GUICreate("GUI In Drag", 300, 300)
$idButton = GUICtrlCreateButton("START Drag", 50, 50, 200, 200)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idButton
            If GUICtrlRead($idButton) = "START Drag" Then
                GUICtrlSetData($idButton, "STOP Drag")
            Else
                GUICtrlSetData($idButton, "START Drag")
            EndIf
    EndSwitch

    If GUICtrlRead($idButton) = "STOP Drag" Then
        $aMPos = MouseGetPos()
        WinMove($hGUI, "", $aMPos[0] - 150, $aMPos[1] - 165)
    EndIf

    Sleep(20)
WEnd

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.