Jump to content

move a gui


Recommended Posts

Case $msg = $GUI_EVENT_PRIMARYDOWN
            $mpos = MouseGetPos()
            $pxcolor = PixelGetColor($mpos[0], $mpos[1], $XSkinGui)
            If Hex($pxcolor) = "00F2F2F2" OR Hex($pxcolor) = "00F1F1F1" Then
                While _IsPressed("1")
                    $wpos = WinGetPos($XSkinGui, "")
                    $npos = MouseGetPos()
                    WinMove($XSkinGui, "", $npos[0], $npos[1])
                WEnd
            Else
            EndIf

This code was meant to enable my gui to be moved on a certain colored area by clicking and dragging. But when I click on an area color 00F2F2F2 it will automatically bring the top left corner where i clicked on the window then ill be able to move it.

Is there a way to click on the window and have it move then and there, without bringing the top left corner under my mouse first?

Try it and you'll know what I mean...

Link to comment
Share on other sites

nowagain - we are not sure what you mean. Do you mean this?

#include <GUIConstantsEx.au3>
Sleep(200)
Global $mpos
$XSkinGui = GUICreate("Squirrely Business")
GUISetState()
While 1
    $msg = GUIGetMsg()
    Sleep(30)
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_EVENT_PRIMARYDOWN
            $mpos = MouseGetPos()
            WinMove($XSkinGui, "", $mpos[0], $mpos[1])
    EndSelect
WEnd

Das Häschen benutzt Radar

Link to comment
Share on other sites

Wow...

I'd just posted two complete solutions for you, then I saw your latest post. So I think I'll delete it. Ask nicely and it might come back.

Original post:

PLEASE remove all your duplicate posts.

There are two easy answers that come to mind.

One is to record the relative positions of the mouse when it's first clicked (mousegetpos())and the upper-left corner of your GUI (wingetpos()), then subtract that difference each time you call WinMove(). So if the mouse was 50 pixels right and 20 pixels down from the corner of your GUI, you'd call WinMove($XSkinGui, "", $npos[0]-50, $npos[1]-20) (naturally you'd have to replace the actual numbers with a variable holding the appropriate calculated offsets)

Something like:

If Hex($pxcolor) = "00F2F2F2" OR Hex($pxcolor) = "00F1F1F1" Then
                $MousePos=MouseGetPos()
                $WinPos=WinGetPos()
                $xOffset=$MousePos[0]-$WinPos[0]
                $yOffset=$MousePos[1]-$WinPos[1]
                While _IsPressed("1")
                    $wpos = WinGetPos($XSkinGui, "")
                    $npos = MouseGetPos()
                    WinMove($XSkinGui, "", $npos[0]-$xOffset, $npos[1]-$yOffset)
                WEnd
            Else
(full disclosure: I didn't test the above code- it may require tweaking)

The easier way is to create a label where you want users to be able to click and drag the window, set the background color to whatever you want (GUICtrlSetBkColor(-1,0xF1F1F1)), and give it an extended style of $GUI_WS_EX_PARENTDRAG (or 0x00100000). That way, it functions as a drag handle natively.

Hope that helps

...and really, delete all those bumps posted within a minute of each other. Stuff like that makes people (or me, at least) less inclined to help.

Restored because he deleted all the bumps referenced.

...just watch your 'joking' before you've viewed as a member of the community that deserves humoring.

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
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...