Here are three examples that I copied from some of my programs.
VB Code:
  1. Private Type RECT
  2.     Left As Long
  3.     Top As Long
  4.     Right As Long
  5.     Bottom As Long
  6. End Type
  7.  
  8. Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
  9. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  10.  
  11. 'This Moves The Mouse To X (Close) Button
  12. Dim Rec As RECT
  13.     'Get Left, Right, Top and Bottom of Form1
  14.     GetWindowRect Form1.hwnd, Rec
  15.     'Set Cursor position on X
  16.     SetCursorPos Rec.Right - 15, Rec.Top + 15
  17.  
  18. 'This will automatically move the mouse to the control that has focus.
  19. Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
  20.  
  21. Private Sub MoveMouseCursor()
  22.  
  23. Dim x As Long
  24. Dim y As Long
  25. Dim z As Long
  26.  
  27. If Me.BorderStyle = 0 Then
  28.  
  29.     x = Me.ActiveControl.Left \ Screen.TwipsPerPixelX + _
  30.     ((Me.ActiveControl.Width / 2) / Screen.TwipsPerPixelX) + _
  31.     (Me.Left / Screen.TwipsPerPixelX)
  32.  
  33.     y = Me.ActiveControl.Top \ Screen.TwipsPerPixelY + _
  34.     ((Me.ActiveControl.Height / 2) / Screen.TwipsPerPixelY) + _
  35.     (Me.Top / Screen.TwipsPerPixelY)
  36.  
  37. Else
  38.  
  39.     x = Me.ActiveControl.Left \ Screen.TwipsPerPixelX + _
  40.     ((Me.ActiveControl.Width / 2 + 60) / Screen.TwipsPerPixelX) + _
  41.     (Me.Left / Screen.TwipsPerPixelX)
  42.  
  43.     y = Me.ActiveControl.Top \ Screen.TwipsPerPixelY + _
  44.     ((Me.ActiveControl.Height / 2 + 360) / Screen.TwipsPerPixelY) + _
  45.     (Me.Top / Screen.TwipsPerPixelY)
  46.  
  47. End If
  48.  
  49. z = SetCursorPos(x, y)
  50.  
  51. End Sub
  52.  
  53. 'Useage:   Call MoveMouseCursor
  54.  
  55. 'This routine will automatically move the mouse to any control on your form that has a hWnd property.
  56. Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
  57. Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  58.  
  59. Private Type RECT
  60.         Left As Long
  61.         Top As Long
  62.         Right As Long
  63.         Bottom As Long
  64. End Type
  65.  
  66. Private Sub MoveMouse(ByVal hWnd As Long)
  67.    
  68.     Dim lpRect As RECT
  69.    
  70.     GetWindowRect hWnd, lpRect
  71.  
  72.     SetCursorPos lpRect.Left + (lpRect.Right - lpRect.Left) \ 2, _
  73.         lpRect.Top + (lpRect.Bottom - lpRect.Top) \ 2
  74.  
  75. End Sub
  76.  
  77. 'Usage:   Call MoveMouse(Command2.hWnd)
Hope these routines help.