Jump to content

Gui Position at mouse coordinates


PaLmeTToX
 Share

Go to solution Solved by JohnOne,

Recommended Posts

Hello All

 

I have an idea that i would like to create a gui that pops up when the middle mouse click & alt is pressed. When pressed a second time it disappears.  I would like it to use the MouseGetPos() value to place the gui at the cursor psosition. 

I am lost and not sure what to do. When I place $aPos = MouseGetPos() inside the loop to refresh the variable , i get error variable is not declared and wont run. When I place the $aPos = MouseGetPos() outside the loop it doesn't refresh the current mouse position and uses the mouse position coordinates at the start of the program and doesn't refresh.  Does anyone have any hints?

#Region    ;************ Includes ************
#Include <GUIConstantsEx.au3>
#include <misc.au3>
#EndRegion ;************ Includes ************



Example1()

Func Example1()
    Local $msg
        Local $aPos = MouseGetPos()
     $GUI2 = GUICreate("CHILD", 110, 10, $aPos[0], $aPos[1]) ; will create a dialog box that when displayed is centered

    ; Run the GUI until the dialog is closed
    While 1
         Sleep(100)
        $msg = GUIGetMsg()
        
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

        If _IsPressed(04) AND _IsPressed(12) Then
            If BitAND(WinGetState($GUI2), 2) Then
                GUISetState(@SW_HIDE, $GUI2)
            Else
                GUISetState(@SW_SHOW, $GUI2)
            EndIf
        EndIf

    WEnd

    GUIDelete()
EndFunc   ;==>Example1

Thank you for your time

Link to comment
Share on other sites

  • Solution

Nothing springs immediately to mind as to what might be wrong, looks fine except for I'd remove the sleep function.

Leave the Local $aPos = MouseGetPos() where it is and add $aPos = MouseGetPos() in loop.

Use WinMove to update its position, but only after a check to see if it has actually moved to avoid flicker.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

PaLmeTToX,

See comment in code...

#Region    ;************ Includes ************
#Include <GUIConstantsEx.au3>
#include <misc.au3>
#EndRegion ;************ Includes ************



Example1()

Func Example1()
    Local $msg
        Local $aPos = MouseGetPos()
     $GUI2 = GUICreate("CHILD", 110, 10, $aPos[0], $aPos[1]) ; will create a dialog box that when displayed is centered

    ; Run the GUI until the dialog is closed
    While 1
         Sleep(100)
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

        If _IsPressed(04) AND _IsPressed(12) Then
            If BitAND(WinGetState($GUI2), 2) Then
                GUISetState(@SW_HIDE, $GUI2)
            Else
                winmove($gui2,'',mousegetpos()[0], mousegetpos()[1])  ; <--- do something like this (not tested)
                GUISetState(@SW_SHOW, $GUI2)
            EndIf
        EndIf

    WEnd

    GUIDelete()
EndFunc   ;==>Example1

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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