Win32API Example - GetMouse
Language(s):Visual Basic 6.0
Category(s):API

Getting the X and Y coordinates of the Mouse.

' Win32API Example - GetMouse 

' Jon Vote 

' 02/2002 

' 1) Create a new project. Form1 will be created by default.
' 2) Add a label to the form. 
' 3) Paste the following code into Form1. 

' --- Begin code for Form1

'Win32API Example - GetMouse
'
'Jon Vote
'
'02/2002
'
Option Explicit
        
Private Type POINTAPI
        x As Long
        y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  
  Dim lngX As Long
  Dim lngY As Long
  
  Call GetMouse(lngX, lngY)
  Me.Caption = "Win32API - GetMouse X=" & lngX & " Y=" & lngY
  
End Sub

Sub GetMouse(MouseX As Long, MouseY As Long)

'**
'** - returns current mouse x and y in
'** - twips
'**
    Dim mousexy As POINTAPI

    Call GetCursorPos(mousexy)
    MouseX = (mousexy.x * Screen.TwipsPerPixelX)
    MouseY = (mousexy.y * Screen.TwipsPerPixelY)

End Sub

' --- End code for Form1 ---

This article has been viewed 3773 times.
The examples on this page are presented "as is". They may be used in code as long as credit is given to the original author. Contents of this page may not be reproduced or published in any other manner what so ever without written permission from Idioma Software Inc.