Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

Determine the location of the mouse pointer

This 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.
-------------------------------------------------

Download VB4 Sample





Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.