Results 1 to 4 of 4

Thread: Getting the pos of the mouse

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Question

    How can I get the x an y pos of the mouse?

  2. #2
    Guest
    Use the GetCursorPos and the WindowFromPoint Api functions to get the position of the mouse.

    Code:
    Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _
    ByVal yPoint As Long) As Long
    
    Type POINTAPI
        x As Long
        y As Long
    End Type
    
    Dim P As POINTAPI
    K$ = GetCursorPos(P)
    J$ = WindowFromPoint(P.x, P.y)

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'this will show it anywhere on the form but not
    'when it's over other controls 
    'find the mouse position anywhere on screen
    'other than over the taskbar if visible
    'text1 & text2  (2 textboxes)
    'click anywhere on form to unload
    
    
    Option Explicit
    
    Private Sub Form_Activate()
      Me.BorderStyle = 0  'none
      Me.WindowState = 2  'max
    End Sub
    
    Private Sub Form_Click()
      Unload Me
      Set Form1 = Nothing
      
    End Sub
    
    
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      Text1.Text = X
      Text2.Text = Y
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Guest
    Try this. Put the following into a Form with a Timer

    Code:
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    Dim prevX, prevY
    
    
    Private Sub Timer1_Timer()
    
        Dim PT As POINTAPI
        
        GetCursorPos PT
        
        If PT.x <> prevX Then Print PT.x
        If PT.y <> prevY Then Print PT.y
        prevX = PT.x: prevY = PT.y
        
    End Sub

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