Hello everyone. I know how to get the X and Y coordinates of a foreign application, but like to know if there is any faster and easier method. Currently, I am using GetWindowRect.
Thank You
Printable View
Hello everyone. I know how to get the X and Y coordinates of a foreign application, but like to know if there is any faster and easier method. Currently, I am using GetWindowRect.
Thank You
You can use ClienttoWindow API, but i'm not sure if it's faster in any way.
Hello Kedaman!
Long time no talk to. Thank you for replying but there is no API call ClientToWindow. Do you mean ClientToScreen? I am going to play around with it now.
Kedaman! This is very interesting. Try this code by stepping through it with F8. Make sure you step through it with F8. I got two different results for the X and Y.
Drop it into a form that is not maximize during run time.
Thanks for introducing a new API to me, Kedaman.Code:Option Explicit
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long
Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Click()
Dim p_Positon As POINTAPI
Call ClientToScreen(Me.hwnd, p_Positon)
Dim r_Positon As Rect
Call GetWindowRect(Me.hwnd, r_Positon)
Call SetCursorPos(p_Positon.X, p_Positon.Y)
Call SetCursorPos(r_Positon.Left, r_Positon.Top)
End Sub
Well, you use a pointapi to retrive the position
I am not quite sure what you mean, but I used both API to see the difference. The ClientToScreen uses a PointAPI to get the position. The GetWindowRect uses Rect to get Left and Top.
sorry, wrote that before you posted, such things happens to me all the time :( well, have fun with it :)
I think use the GetCursorPos API will do.
Code:Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private pt As POINTAPI
Private Sub Command1_Click()
Dim dl As Long
Dim PosX As Long
Dim PosY As Long
dl = GetCursorPos(pt)
PopX = ScaleX(pt.x, vbPixels, vbTwips)
PopY = ScaleY(pt.y, vbPixels, vbTwips)
Msgbox "Current Mouse Position is " & PopX & ", " & PopY
End Sub