|
Determine the location of the mouse pointerThis example enables you to determine the location of the mouse pointer in relation to the entire screen. In order to determine this information you will need to define a UDT User Defined Type (PointAPI), declare the API SUB to extract the information, and finally a call to invoke the API call. Let's start by placing the UDT and the API declaration into a module. These lines look like the following:
Type PointAPI
x As Long
y As Long
End Type
Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Finally, you will need to place the next three lines of code into an event procedure (such as Form_MouseMove). You can use any event procedure to call this - including a TIMER event.
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Pnt As PointAPI ' Declare a variable to use the UDT
GetCursorPos Pnt ' Call the API to return the x and y coordinates of the mouse pointer
Me.Cls
Me.Print "MousePointer is located at "; Pnt.X; ","; Pnt.Y
End Sub
------------------------------------------------- Original tip and project submitted by Jeff Hargett of the VB4UandMe site. Minor text editing by Burt Abreu. -------------------------------------------------
|
Quick searches: Site Search | Advanced Site Search |
|
By using this site you agree to its terms and conditions VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc. |