11、怎样找到鼠标指针的XY坐标?*API函数声明 Type POINTAPI x As Long y As Long End Type Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long 调用: GetCursorPos z print z.x print z.y
Option ExplicitPublic Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Public Type POINTAPI x As Long y As Long End TypePublic Type DGfor3 ponX As Long ponY As Long MDC As Long End TypePublic Function MouseDC() As DGfor3 On Error Resume Next Dim Cur As POINTAPI GetCursorPos Cur MouseDC.MDC = WindowFromPoint(Cur.x, Cur.y) MouseDC.ponX = Cur.x MouseDC.ponY = Cur.y End Function
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '鼠标移动事件处理程序,X,Y就是鼠标位置的坐标 End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'PictureBox中鼠标移动事件处理程序,X,Y就是鼠标位置的坐标 'button对应鼠标各个按钮的状态,左键1,右键2,两个键3 End SubPrivate Sub Picture1_MouseUp(button As Integer, shift As Integer, x As Single, y As Single) 'PictureBox中鼠标按键抬起事件处理程序,X,Y就是鼠标位置的坐标 'button对应鼠标各个按钮的状态,左键1,右键2,两个键3 End SubPrivate Sub Picture1_MouseDown(button As Integer, shift As Integer, x As Single, y As Single) 'PictureBox中鼠标按键按下事件处理程序,X,Y就是鼠标位置的坐标 'button对应鼠标各个按钮的状态,左键1,右键2,两个键3 End Sub
Type POINTAPI
x As Long
y As Long
End Type
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
调用:
GetCursorPos z
print z.x
print z.y
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End TypePublic Type DGfor3
ponX As Long
ponY As Long
MDC As Long
End TypePublic Function MouseDC() As DGfor3
On Error Resume Next
Dim Cur As POINTAPI
GetCursorPos Cur
MouseDC.MDC = WindowFromPoint(Cur.x, Cur.y)
MouseDC.ponX = Cur.x
MouseDC.ponY = Cur.y
End Function
'鼠标移动事件处理程序,X,Y就是鼠标位置的坐标
End Sub
'PictureBox中鼠标移动事件处理程序,X,Y就是鼠标位置的坐标
'button对应鼠标各个按钮的状态,左键1,右键2,两个键3
End SubPrivate Sub Picture1_MouseUp(button As Integer, shift As Integer, x As Single, y As Single)
'PictureBox中鼠标按键抬起事件处理程序,X,Y就是鼠标位置的坐标
'button对应鼠标各个按钮的状态,左键1,右键2,两个键3
End SubPrivate Sub Picture1_MouseDown(button As Integer, shift As Integer, x As Single, y As Single)
'PictureBox中鼠标按键按下事件处理程序,X,Y就是鼠标位置的坐标
'button对应鼠标各个按钮的状态,左键1,右键2,两个键3
End Sub
一般的,在鼠标的down\up\move事件中都可以捕获鼠标的坐标。