Sign in to follow this  
Followers 0

cursor position !

10 posts in this topic

Posted (edited)

Gets the mouse cursor position relative to CONTROL ? 

 
Edited by Mrbenkali

Share this post


Link to post
Share on other sites



Posted

Hi,

Yes you can, think a little.

Share this post


Link to post
Share on other sites

Posted

you can do it in my example !

Share this post


Link to post
Share on other sites

Posted

you can do it in my example !

:blink:

Share this post


Link to post
Share on other sites

Posted (edited)

Hints: Ctrl coords, Mouse coords; Difference.

Edited by FireFox

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted (edited)

You're losing more time to post than to find how to do it knowing that I almost did it for you (without code).

Edited by FireFox

Share this post


Link to post
Share on other sites

Posted

FireFox already told you.

You already know the coordinates of the control.  You know how to get the coordinates of the mouse.  The rest is arithmetic.

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

AH OK THANK YOU 

FireFox   :thumbsup: 

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