Results 1 to 3 of 3

Thread: Getting the mouse location on the screen

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    44

    Question

    (* Sorry about my english , i am from Israel..)

    Hi
    How can i get the mouse location of the mouse with API function (x and y for location or whatever...)
    what is the name of the function? i will be happy to know how to use it (can you give me an example maybe? )

    Thanks!
    Namo.


  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    No Problem, There's 2 APIs to use

    they all use
    Code:
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    which is a type used to store the mouse position


    the first is
    Code:
    Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
    this fills the structure passed to lpPoint with the coordinates of the mouse on the screen

    the other one is
    Code:
    Private Declare Function ScreenToClient Lib "user32" Alias "ScreenToClient" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    this translates the coordinates in lpPoint from screen coods to the coords of a particular window.

    The coords of the mouse position you get are in pixels, you need the scalex and scaley methods to translate this into twips.

    for example

    Code:
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim px As Single
    Dim py As Long
    Dim apiPoint As POINTAPI
    
    GetCursorPos apiPoint   'gets the screen position of the cursor in pixels
    
    ScreenToClient Form1.hwnd, apiPoint 'Tanslates to window coords, still in pixels
    
    px = Form1.ScaleX(apiPoint.x, vbPixels, vbTwips)    'scales coords to pixels
    py = Form1.ScaleY(apiPoint.y, vbPixels, vbTwips)
    
    MsgBox x - px   'will always return 0
    MsgBox y - py
    
    
    End Sub
    hope this helps




  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    44

    Thanks

    Thank you very very much

    Nimrod/namo

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