Results 1 to 3 of 3

Thread: [RESOLVED] Rotating Mouse Cursor Position

  1. #1

    Thread Starter
    Android OpenGL ES Guru Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,278

    Resolved [RESOLVED] Rotating Mouse Cursor Position

    I'm having issues using the SetCursorPos API on rotating the mouse cursor in a circular motion around a certain point. My code looks ok though. I don't have time to make a sample app since my main projects too big to upload (not to mention I'm leaving work right now), but can anyone provide a solution for me? I'll tackle on it tommorow. Thanks in advance, and rep points will be given out to those who solve my problem.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Lightbulb Re: Rotating Mouse Cursor Position

    Create a form with a timer (Timer1) and a command button (Command1) and paste the following code:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SetCursorPos Lib "user32" _
    4.                         (ByVal X As Long, _
    5.                          ByVal Y As Long) As Long
    6.  
    7. Private Declare Function GetWindowRect Lib "user32" _
    8.                         (ByVal hwnd As Long, _
    9.                          lpRect As RECT) As Long
    10.  
    11. Private Type RECT
    12.   Left As Long
    13.   Top As Long
    14.   Right As Long
    15.   Bottom As Long
    16. End Type
    17.  
    18. Private Type POINTAPI
    19.   X As Long
    20.   Y As Long
    21. End Type
    22.  
    23. Private ptCenter As POINTAPI
    24.  
    25. 'Mouse position from ptCenter.
    26. Private Angle  As Single  'In radians
    27. Private Radius As Long    'In pixels
    28.  
    29. Private Const ANGLE_INCREMENT As Single = 0.25
    30.  
    31. Private Sub Form_Load()
    32.   Dim rectButton As RECT
    33.  
    34.   ScaleMode = vbPixels
    35.  
    36.   'Spin the mouse around the center of the command button.
    37.   GetWindowRect Command1.hwnd, rectButton
    38.   ptCenter.X = (rectButton.Left + rectButton.Right) \ 2
    39.   ptCenter.Y = (rectButton.Top + rectButton.Bottom) \ 2
    40.  
    41.   Timer1.Enabled = False
    42.   Timer1.Interval = 200
    43.  
    44.   Command1.Default = True
    45.  
    46.   Radius = Command1.Width \ 2
    47. End Sub
    48.  
    49. Private Sub Command1_Click()
    50.   Angle = 0
    51.   Timer1.Enabled = Not Timer1.Enabled
    52. End Sub
    53.  
    54. Private Sub Timer1_Timer()
    55.   AdvanceMouse
    56. End Sub
    57.  
    58. Private Sub AdvanceMouse()
    59.   Dim ptNew As POINTAPI
    60.  
    61.   LSet ptNew = ptCenter
    62.  
    63.   With ptNew
    64.     .X = .X + Cos(Angle) * Radius
    65.     .Y = .Y + Sin(Angle) * Radius
    66.  
    67.     SetCursorPos .X, .Y
    68.   End With
    69.  
    70.   Angle = Angle + ANGLE_INCREMENT
    71. End Sub

  3. #3

    Thread Starter
    Android OpenGL ES Guru Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,278

    Re: Rotating Mouse Cursor Position

    Thanks bro!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width