SoonerToucan
June 18th, 2004, 05:57 PM
I am attempting to set the position of the mouse to set coords in another window. I have been able to set the position by using SetCursorPos but for some reason I cannot get it to set the position in the other window. I am pretty sure I need to set the window by using the ClietToScreen() yet I am not able to get it to work. I am using the following code
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As IntPtr, _
ByVal lpPoint As POINTAPI) As Integer
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, _
ByVal y As Integer) As Integer
Private Structure POINTAPI
Dim X As Long
Dim Y As Long
End Structure
Dim pt As POINTAPI
pt.X = txtX.Text
pt.Y = txtY.Text
ClientToScreen(myHandle, pt)
SetCursorPos(pt.X, pt.Y)
I have also tried varriations of this:
Dim pt As POINTAPI
ClientToScreen(myHandle, pt)
pt.X = pt.X + txtX.Text
pt.Y = pt.Y + txtY.Text
SetCursorPos(pt.X, pt.Y)
I have the correct handle for the window (tried both as Integer and IntPtr) when I try the program with out the ClientToScreen function the mouse is moved to the coords based on my desktop, not on the window whos handle I pass. If I use the Integer or IntPtr it erros out with (Additional information: Object reference not set to an instance of an object)
Any help would be appreciated,
Patrick
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As IntPtr, _
ByVal lpPoint As POINTAPI) As Integer
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, _
ByVal y As Integer) As Integer
Private Structure POINTAPI
Dim X As Long
Dim Y As Long
End Structure
Dim pt As POINTAPI
pt.X = txtX.Text
pt.Y = txtY.Text
ClientToScreen(myHandle, pt)
SetCursorPos(pt.X, pt.Y)
I have also tried varriations of this:
Dim pt As POINTAPI
ClientToScreen(myHandle, pt)
pt.X = pt.X + txtX.Text
pt.Y = pt.Y + txtY.Text
SetCursorPos(pt.X, pt.Y)
I have the correct handle for the window (tried both as Integer and IntPtr) when I try the program with out the ClientToScreen function the mouse is moved to the coords based on my desktop, not on the window whos handle I pass. If I use the Integer or IntPtr it erros out with (Additional information: Object reference not set to an instance of an object)
Any help would be appreciated,
Patrick