Sign in to follow this  
Followers 0
MerkurAlex

Mouse position inside a window

6 posts in this topic

I need a quick and simple way to figure out where the mouse is inside of a window not like mousegetpos()


[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Share this post


Link to post
Share on other sites



#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <WinAPI.au3>
Opt('MustDeclareVars', 1)

_Main()

Func _Main()
   Local $hwnd = GUICreate("Example", 200, 200)
   Local $tpoint = DllStructCreate("int X;int Y")
   DllStructSetData($tpoint, "X", 641)
   DllStructSetData($tpoint, "Y", 459)
   GUISetState(@SW_SHOW)
   Sleep(1000)
   _WinAPI_ScreenToClient($hwnd, $tpoint)
   MsgBox(0, "_WINAPI_ScreenToClient Example", "Screen Cordinates of 641,459 is x,y position of client: " & @LF & _
         "X: " & DllStructGetData($tpoint, "X") & @LF & _
         "Y: " & DllStructGetData($tpoint, "Y") & @LF)
EndFunc   ;==>_Main


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

hi,

what is the difference between client coordinated and screen coordinates?

Share this post


Link to post
Share on other sites

Client is the actual window co-ords. If you look at these examples, it might clear it up a little more. :)

#AutoIt3Wrapper_au3check_parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
; _Win_API Examples
; Function:  _WinApi_

#include <WinAPI.au3>
Opt('MustDeclareVars', 1)

Example_Internal()

Func Example_Internal()
    Local $hwnd = GUICreate("Example", 200, 200)
    Local $tpoint = DllStructCreate("int X;int Y")
    DllStructSetData($tpoint, "X", 641)
    DllStructSetData($tpoint, "Y", 459)
    GUISetState(@SW_SHOW)
    Sleep(1000)
    _WinAPI_ScreenToClient($hwnd, $tpoint)
    MsgBox (0, "_WINAPI_ClientToScreen Example", "Screen Cordinates of client's x,y position: 100,160 is: " & @LF & _
    "X: " & DllStructGetData($tpoint, "X") & @LF & _
    "Y: " & DllStructGetData($tpoint, "Y") & @LF)
EndFunc  ;==>Example_Internal

#AutoIt3Wrapper_au3check_parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
; _Win_API Examples
; Function:  _WinApi_

#include <WinAPI.au3>
Opt('MustDeclareVars', 1)

Example_Internal()

Func Example_Internal()
    Local $hwnd = GUICreate("Example", 200, 200)
    Local $tpoint = DllStructCreate("int X;int Y")
    DllStructSetData($tpoint, "X", 100)
    DllStructSetData($tpoint, "Y", 160)
    GUISetState(@SW_SHOW)
    Sleep(1000)
    _WinAPI_ClientToScreen($hwnd, $tpoint)
    MsgBox (0, "_WINAPI_ClientToScreen Example", "Screen Cordinates of client's x,y position: 100,160 is: " & @LF & _
    "X: " & DllStructGetData($tpoint, "X") & @LF & _
    "Y: " & DllStructGetData($tpoint, "Y") & @LF)
EndFunc  ;==>Example_Internal

Share this post


Link to post
Share on other sites

hi, first Thanks,

now lets see If i got it: you mean client coordinates in the Examples are where is the client resides from the X,Y declared values? meaning that -28,-54

result is where the client is away from 641,459 ? (the X of the client is away from 641 in -28 pixles, and the Y of client is away -54 from 459) right?

if so, how will it help the guy with his question about where the mouse is? this solution gives where the GUI is from X,Y or not?

Share this post


Link to post
Share on other sites

hi, first Thanks,

now lets see If i got it: you mean client coordinates in the Examples are where is the client resides from the X,Y declared values? meaning that -28,-54

result is where the client is away from 641,459 ? (the X of the client is away from 641 in -28 pixles, and the Y of client is away -54 from 459) right?

if so, how will it help the guy with his question about where the mouse is? this solution gives where the GUI is from X,Y or not?

If _ScreenToClient resides in the co-ords of the window + witdth and height. :)

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