Determine the location of the mouse pointer
By: Unknown Date: 24/09/1998

This source code 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 User define 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 Integer
    y As Integer
End Type

Declare Sub GetCursorPos Lib "User32" (lpPoint As PointAPI)

Finally, you will need to place the next three lines of code into an event procedure (such as Form_Click). You can use any event procedure to call this - including a Timer event.

Dim Pnt As PointAPI
GetCursorPos Pnt

Cursor coordinates will be stored in Pnt.x and Pnt.y.

Click Here!


Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
Webmaster's e-mail: webmaster@vbprogzone.cjb.net
Hosted by InWind: www.inwind.it