Jump to content

Dragging image


Recommended Posts

Trying to drag an image around, but I'd like it not to drag from the top left, but from wherever the mouse is on the image. By the way, if your going to copy the code, just replace my image with one of your own that doesn't fit in the GUI.

Code:

#include <GUIConstants.au3>

Opt("MouseCoordMode", 0)

GUICreate("Test", 300, 200)

$Image = GUICtrlCreatePic("C:\Documents and Settings\User\My Documents\My Pictures\EPIX.bmp", 0, 0, 400, 330)
GUICtrlSetCursor($Image, 9)

GUISetState()
While 1
    $msg = GUIGetMsg()
    $Mmsg = GUIGetCursorInfo()
    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    If $Mmsg[4] = $Image Then
        While $Mmsg[2] = 1
            $Mmsg = GUIGetCursorInfo()
            GUICtrlSetPos($Image, $Mmsg[0], $Mmsg[1])
        WEnd
    EndIf
WEnd
Exit

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

Heres a script I threw together a while ago, this one you can click & hold the image and you can drag it around and let go of it. just replace test.bmp with whatever your using

EDIT: Okay I edited it to drag from the very point you clicked it at

#include <GUIConstants.au3>
#include <Misc.au3>
$Form1 = GUICreate("Pick up", 1000, 900, 0, 0)
$Pic1 = GUICtrlCreatePic("test.bmp", 96, 88, 100, 100)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Pic1
            _PickUp("Pick up",$Pic1,100,100)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _PickUp($z_WinName,$z_control,$z_controlWidth,$z_controlHeight)
    ;Requires #include <Misc.au3>
    $dll = DllOpen("user32.dll")
    $Mpos = MouseGetPos()
    $Wpos = WinGetPos($z_WinName)
    $Cpos = ControlGetPos($z_WinName,"",$z_control)
    $Additional0 = $Mpos[0] - ($Wpos[0] + $Cpos[0]) ;Add the position of the window and the control
    $Additional1 = $Mpos[1] - ($Wpos[1] + $Cpos[1]) ;Then subtract it from the mouse position
    Do
    $Mpos = MouseGetPos()
    $Wpos = WinGetPos($z_WinName)
    $XCpos = $Mpos[0] - $Wpos[0] - $Additional0 ;The Addition vars add the extra pixels from the
    $YCpos = $Mpos[1] - $Wpos[1] - $Additional1 ;mouse's position
    ControlMove($z_WinName,"",$z_control,$XCpos,$YCpos)
    ToolTip($XCpos & " " & $YCpos)
Until Not(_IsPressed(01,$dll))
ToolTip("")
    DllClose($dll)
EndFunc
Edited by VindicatorOmega

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

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...