GetCursorPos VB声明
Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
说明
获取鼠标指针的当前位置
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpPoint POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构 先得到屏幕坐标,再计算不就可以了吗??
Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
说明
获取鼠标指针的当前位置
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpPoint POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构 先得到屏幕坐标,再计算不就可以了吗??
http://ygyuan.go.163.com/
http://ygyuan.3322.net/
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate Type POINTAPI
x As Long
y As Long
End Type
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lPos As POINTAPI
Dim lhWnd As Long
Dim lRect As RECT
Dim lX As Long, lY As Long
GetCursorPos lPos
lhWnd = WindowFromPoint(lPos.x, lPos.y)
GetWindowRect lhWnd, lRect
lX = lPos.x - lRect.Left
lY = lPos.y - lRect.Top
Debug.Print lX, lY
End Sub
ScreenToClient(hwnd,point) 得到全屏幕的坐标对应在具体窗口的坐标.
和VB中的单位怎么换算?
而且,如果MSHFlexGrid有滚动条
那么如何才能知道鼠标右键放开的时候究竟是在哪个单元格上方呢?
我需要知道的就是鼠标右键放开的时候究竟是在哪个单元格上方。
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate Type POINTAPI
x As Long
y As Long
End Type
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lPos As POINTAPI
Dim lhWnd As Long
Dim lRect As RECT
Dim lX As Long, lY As Long
GetCursorPos lPos
lhWnd = WindowFromPoint(lPos.x, lPos.y)
If lhWnd = MSFlexGrid1.hwnd Then 'changed
GetWindowRect lhWnd, lRect
lX = lPos.x - lRect.Left
lY = lPos.y - lRect.Top
MsgBox (Str(lX) + "," + Str(lY))
End If
End Sub
MsgBox x+ "," + y
End Sub