Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
'This Moves The Mouse To X (Close) Button
Dim Rec As RECT
'Get Left, Right, Top and Bottom of Form1
GetWindowRect Form1.hwnd, Rec
'Set Cursor position on X
SetCursorPos Rec.Right - 15, Rec.Top + 15
'This will automatically move the mouse to the control that has focus.
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Sub MoveMouseCursor()
Dim x As Long
Dim y As Long
Dim z As Long
If Me.BorderStyle = 0 Then
x = Me.ActiveControl.Left \ Screen.TwipsPerPixelX + _
((Me.ActiveControl.Width / 2) / Screen.TwipsPerPixelX) + _
(Me.Left / Screen.TwipsPerPixelX)
y = Me.ActiveControl.Top \ Screen.TwipsPerPixelY + _
((Me.ActiveControl.Height / 2) / Screen.TwipsPerPixelY) + _
(Me.Top / Screen.TwipsPerPixelY)
Else
x = Me.ActiveControl.Left \ Screen.TwipsPerPixelX + _
((Me.ActiveControl.Width / 2 + 60) / Screen.TwipsPerPixelX) + _
(Me.Left / Screen.TwipsPerPixelX)
y = Me.ActiveControl.Top \ Screen.TwipsPerPixelY + _
((Me.ActiveControl.Height / 2 + 360) / Screen.TwipsPerPixelY) + _
(Me.Top / Screen.TwipsPerPixelY)
End If
z = SetCursorPos(x, y)
End Sub
'Useage: Call MoveMouseCursor
'This routine will automatically move the mouse to any control on your form that has a hWnd property.
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
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 MoveMouse(ByVal hWnd As Long)
Dim lpRect As RECT
GetWindowRect hWnd, lpRect
SetCursorPos lpRect.Left + (lpRect.Right - lpRect.Left) \ 2, _
lpRect.Top + (lpRect.Bottom - lpRect.Top) \ 2
End Sub
'Usage: Call MoveMouse(Command2.hWnd)