Results 1 to 4 of 4

Thread: Mouse X And Y

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Mouse X And Y

    Is there a way to determine the mouse x and y coordinates in relation to the screen itself VS in relation to the form?

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    if you know the x and y coords for the mouse on the form, then you should be able to use the form's Left\Top\WidthHeight properties and the screen's Height\Width properties to calculate it...???
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Just use ClientToScreen API:
    VB Code:
    1. Private Type POINTAPI
    2.     X As Long
    3.     Y As Long
    4. End Type
    5. Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    6.  
    7.  
    8. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.     Dim pt As POINTAPI
    10.  
    11.     pt.X = X \ Screen.TwipsPerPixelX
    12.     pt.Y = Y \ Screen.TwipsPerPixelY
    13.     Call ClientToScreen(Text1.hwnd, pt)
    14.     Debug.Print "X: " & pt.X & "  Y: " & pt.Y
    15. End Sub

  4. #4
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    use the GetCursorPos API call:

    Code:
    Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
    Type POINTAPI
            x As Long
            y As Long
    End Type
    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

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