
 |
Visual Basic Programmer's Resources/Examples:
Get Mouse Position:
' Instructions:
' 1) Paste the following code into a new project
' 2) Run the project. As you move the mouse, the
' mouse coordinates will appear in the form
' caption.
' This sample code is presented as is.
' Although every reasonable effort has been
' made to insure the correctness of the example
' below, Idioma Software Inc. makes no warranty
' of any kind with regard to this program sample
' either implicitly or explicitly.
' This program example may be freely distributed for the
' use of writing computer programs only. Any other use of
' this material requires written permission from Idioma Software inc.
' (c) 2000 Idioma Software inc. All rights reserved.
' Title: Get Mouse Position
' Platform: Visual Basic - 32 bit
' Author: Jon Vote
' Contact: jon@idioma-software.com
' Date: 02/2000
'
Option Explicit
'Declare as public for use in external module
Private Type POINTAPI
X As Long
Y As Long
End Type
'Declare as public for use in external module
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
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
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim iX As Long
Dim iY As Long
Call GetMouse(iX, iY)
Me.Caption = "Mouse position: " & iX & ":" & iY
End Sub
|