Sign in to follow this  
Followers 0
=sinister=

drag-able image

8 posts in this topic

is there any way I can make an image, that i set using GUI, drag-able? Really apreciate some help! Thanks!

Share this post


Link to post
Share on other sites



You could take a look at mousegetpos(), and use the coords after an _IsPressed as the coords to the picture to possibly move it.

I remember Cyberslug doing something similiar with resizing a lable with a similar method as above.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I'm rusty, but this might help:

#include <GuiConstants.au3>

; Constants for use with the return result of GUIGetCursorInfo
; so that I don't have to comment my code :)
Global Const $X = 0, $Y = 1, $PRIMARY_DOWN = 2, $SECONDARY_DOWN = 3, $CTRL = 4

$GUI = GuiCreate("Example of mouse down and drag...")

$label = GuiCtrlCreateLabel("This is a label", 10, 10, 100, 100)
GuiCtrlSetBkColor($label, 0xFF0000)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        
    $mouse = GUIGetCursorInfo($GUI)
    If $mouse[$PRIMARY_DOWN] And $mouse[$CTRL] = $label Then
        $LabelPos = ControlGetPos($GUI,"",$label)
        $lwidth = $LabelPos[2]
        $lheight = $LabelPos[3]
        GuiCtrlSetPos( $label, $mouse[$X] - $lwidth/2,  $mouse[$Y] - $lheight/2 )
    EndIf
WEnd

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Wasn't there like, a ReleaseCapture UDF that did this with like 1 simple DllCall... I know I used to have it somewhere here...

EDIT: Nevermind, that's just if you want to move the WHOLE GUI, not a specific control. Although CyberSlug's example works very nicely.

Edited by layer

FootbaG

Share this post


Link to post
Share on other sites

Replaced: $label = GuiCtrlCreateLabel("This is a label", 10, 10, 100, 100)

With: $label = GUICtrlCreatePic(@DocumentsCommonDir & "\My Pictures\Sample Pictures\Sunset.jpg", 50, 50, 50, 50)

Works very nice !! B)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Revised code below. The original code would center the image under the mouse when you clicked. The code below is "better" in that you can drag the label near the corner; however, you might have to pick up the label again if you drag the mouse too quickly.

#include <GuiConstants.au3>

; Constants for use with the return result of GUIGetCursorInfo
; so that I don't have to comment my code :)
Global Const $X = 0, $Y = 1, $PRIMARY_DOWN = 2, $SECONDARY_DOWN = 3, $CTRL = 4

$GUI = GuiCreate("Example of mouse down and drag...")

$label = GuiCtrlCreateLabel("This is a label", 10, 10, 100, 100)
GuiCtrlSetBkColor($label, 0xFF0000)

GuiSetState()

Dim $xOffset, $yOffset

While 1
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        
    $mouse = GUIGetCursorInfo($GUI)
    If $mouse[$PRIMARY_DOWN] And $mouse[$CTRL] = $label Then
        $LabelPos = ControlGetPos($GUI,"",$label)
        $lwidth = $LabelPos[2]
        $lheight = $LabelPos[3]
        GuiCtrlSetPos( $label, $mouse[$X] - $xOffset,  $mouse[$Y] - $yOffset)
    Else
        $LabelPos = ControlGetPos($GUI,"",$label)
        $xOffset = $mouse[$X] - $labelPos[0];mouseX - labelX
        $yOffset = $mouse[$Y] - $labelPos[1];mouseY - labelY
    EndIf
WEnd

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Nice one!!... He got his code last night and didn't even thank you... But I'm sure this will come in handy for someone... !!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Revised code below. The original code would center the image under the mouse when you clicked. The code below is "better" in that you can drag the label near the corner; however, you might have to pick up the label again if you drag the mouse too quickly.

#include <GuiConstants.au3>

; Constants for use with the return result of GUIGetCursorInfo
; so that I don't have to comment my code :)
Global Const $X = 0, $Y = 1, $PRIMARY_DOWN = 2, $SECONDARY_DOWN = 3, $CTRL = 4

$GUI = GuiCreate("Example of mouse down and drag...")

$label = GuiCtrlCreateLabel("This is a label", 10, 10, 100, 100)
GuiCtrlSetBkColor($label, 0xFF0000)

GuiSetState()

Dim $xOffset, $yOffset

While 1
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        
    $mouse = GUIGetCursorInfo($GUI)
    If $mouse[$PRIMARY_DOWN] And $mouse[$CTRL] = $label Then
        $LabelPos = ControlGetPos($GUI,"",$label)
        $lwidth = $LabelPos[2]
        $lheight = $LabelPos[3]
        GuiCtrlSetPos( $label, $mouse[$X] - $xOffset,  $mouse[$Y] - $yOffset)
    Else
        $LabelPos = ControlGetPos($GUI,"",$label)
        $xOffset = $mouse[$X] - $labelPos[0];mouseX - labelX
        $yOffset = $mouse[$Y] - $labelPos[1];mouseY - labelY
    EndIf
WEnd
You can fix the dropping the draged item by putting a Do loop following the If statement

If $mouse[$PRIMARY_DOWN] And $mouse[$CTRL] = $label Then
        Do
                $LabelPos = ControlGetPos($GUI,"",$label)
                $lwidth = $LabelPos[2]
                $lheight = $LabelPos[3]
                GuiCtrlSetPos( $label, $mouse[$X] - $xOffset,  $mouse[$Y] - $yOffset)
                $mouse = GUIGetCursorInfo($GUI)
       Until Not $mouse[$PRIMARY_DOWN]

Is there a way to avoid the screen flickering while moving the item?

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