skin 2007-12-3 10:15
如何获得鼠标指正的X,Y坐标
Finding the X and Y co-ordinates of the mouse pointer
In many drawing applications, there is a small area that displays the current cursor position on the screen. This is very simple to do and only requires one Windows API call. The example below brings back the x and y co-ordinates of the current cursor position.
Example:
1. Start a new standard EXE project in Visual Basic; form1 is created by default.
2. Add a standard module to the project by clicking on project on the Visual Basic menu and select 注释:Add Module注释:. Module1 is opened up by default.
3. Type the following, making sure that the API call is on one line
Option Explicit
Type POINTAPI 注释:Declare types
x As Long
y As Long
End Type
Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long 注释:Declare API4. Open up Form1 and add two labels and one timer. Set the interval property of the timer to 1. Open up the code window to form1 and type the following
Option Explicit
Dim z As POINTAPI 注释:Declare variable
** Sub Timer1_Timer()
GetCursorPos z 注释:Get Co-ordinets
Label1 = "x: "