Jump to content

cursor position !


Recommended Posts

How to do in this example 

#include <GUIConstantsEx.au3>

Global $x, $y

Example()

Func Example()
    Local $msg

    HotKeySet("{Esc}", "GetPos")

    GUICreate("Press Esc to Get Pos", 400, 400)
    $x = GUICtrlCreateLabel("0", 10, 10, 50)
    $y = GUICtrlCreateLabel("0", 10, 30, 50)
    $Pic1 = GUICtrlCreatePic("", 10, 40, 250, 250)
    GUISetState()

    ; Run the GUI until the dialog is closed
    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func GetPos()
    Local $a

    $a = GUIGetCursorInfo($Pic1)
    GUICtrlSetData($x, $a[0])
    GUICtrlSetData($y, $a[1])
EndFunc   ;==>GetPos
Link to comment
Share on other sites

Result: You don't even need to get the cursor coords (with the MouseGetPos function).

That was quite hard.

#include <GUIConstantsEx.au3>
 
Local $hGUI = 0, $iLabel1 = 0, $aCi = 0, $aCtrlPos = 0
 
$hGUI = GUICreate("MyGUI")
 
$iLabel1 = GUICtrlCreateLabel("", 10, 10, 100, 13)
 
GUISetState(@SW_SHOW, $hGUI)
 
$aCtrlPos = ControlGetPos($hGUI, "", $iLabel1) ;in case you don't know the control coords
 
While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
 
    $aCi = GUIGetCursorInfo($hGUI)
    If IsArray($aCi) = 0 Then ContinueLoop
 
    GUICtrlSetData($iLabel1, "X: " & $aCi[0] - $aCtrlPos[0] & ", Y: " & $aCi[1] - $aCtrlPos[1])
WEnd
 
GUIDelete($hGUI)
Edited by FireFox
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...