无视控件的全窗口内鼠标坐标获取(很方便)
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
————————————————
Private Sub Timer1_Timer()
Dim P As POINTAPI
GetCursorPos P '获取鼠标在屏幕中的位置
ScreenToClient Me.hwnd, P '转换为本窗体的坐标
Dim t As Boolean
t = P.x >= 0 And P.y >= 0 And P.x < Me.Width / Screen.TwipsPerPixelX And P.y <= Me.Height / Screen.TwipsPerPixelY
If t Then Me.Caption = "x=" & P.x & "y=" & P.y '按像素显示坐标
'If t Then Me.Caption = "x=" & P.x * Screen.TwipsPerPixelX & "y=" & P.y * Screen.TwipsPerPixelY '按缇显示坐标
End Sub
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
————————————————
Private Sub Timer1_Timer()
Dim P As POINTAPI
GetCursorPos P '获取鼠标在屏幕中的位置
ScreenToClient Me.hwnd, P '转换为本窗体的坐标
Dim t As Boolean
t = P.x >= 0 And P.y >= 0 And P.x < Me.Width / Screen.TwipsPerPixelX And P.y <= Me.Height / Screen.TwipsPerPixelY
If t Then Me.Caption = "x=" & P.x & "y=" & P.y '按像素显示坐标
'If t Then Me.Caption = "x=" & P.x * Screen.TwipsPerPixelX & "y=" & P.y * Screen.TwipsPerPixelY '按缇显示坐标
End Sub