
2个回答
展开全部
新建一个工程,添加两个lable,一个command,一个timer
复制以下代码,再生成EXE文件,打开那个文件,即可获取鼠标所在的坐标与句柄
代码如下:
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 Type POINTAPI
x As Long
y As Long
End Type
Dim p As POINTAPI
Private Sub Command1_Click()
GetCursorPos p
Dim hwnd As Long
Dim pt As POINTAPI
GetCursorPos pt '取得鼠标坐标信息
hwnd = WindowFromPoint(p.x, p.y) '获取句柄
If MsgBox("X坐标: " & p.x & " ,Y坐标:" & p.y & " 鼠标指向句柄:" & hwnd & "", vbOKOnly, "查看句柄与坐标") = 6 Then
End If
End Sub
Private Sub Form_Load()
Timer1.Timer = 5
GetCursorPos p
Dim hwnd As Long
Dim pt As POINTAPI
GetCursorPos pt '取得鼠标坐标信息
hwnd = WindowFromPoint(p.x, p.y) '获取句柄
Me.Caption = "坐标与窗口句柄查看器"
Label3.Caption = "X坐标:" & p.x & ",Y坐标:" & p.y & ""
Label1.Caption = " 当前指向窗口句柄: " & hwnd & ""
Command1.Caption = "获取鼠标指向句柄与坐标(&H)"
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Sub timer1_timeR()
GetCursorPos p
Dim hwnd As Long
Dim pt As POINTAPI
GetCursorPos pt '取得鼠标坐标信息
hwnd = WindowFromPoint(p.x, p.y) '获取句柄
Label1.Caption = " 当前指向窗口句柄: " & hwnd & ""
Label3.Caption = "X坐标: " & p.x & " ,Y坐标:" & p.y & ""
End Sub
复制以下代码,再生成EXE文件,打开那个文件,即可获取鼠标所在的坐标与句柄
代码如下:
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 Type POINTAPI
x As Long
y As Long
End Type
Dim p As POINTAPI
Private Sub Command1_Click()
GetCursorPos p
Dim hwnd As Long
Dim pt As POINTAPI
GetCursorPos pt '取得鼠标坐标信息
hwnd = WindowFromPoint(p.x, p.y) '获取句柄
If MsgBox("X坐标: " & p.x & " ,Y坐标:" & p.y & " 鼠标指向句柄:" & hwnd & "", vbOKOnly, "查看句柄与坐标") = 6 Then
End If
End Sub
Private Sub Form_Load()
Timer1.Timer = 5
GetCursorPos p
Dim hwnd As Long
Dim pt As POINTAPI
GetCursorPos pt '取得鼠标坐标信息
hwnd = WindowFromPoint(p.x, p.y) '获取句柄
Me.Caption = "坐标与窗口句柄查看器"
Label3.Caption = "X坐标:" & p.x & ",Y坐标:" & p.y & ""
Label1.Caption = " 当前指向窗口句柄: " & hwnd & ""
Command1.Caption = "获取鼠标指向句柄与坐标(&H)"
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Sub timer1_timeR()
GetCursorPos p
Dim hwnd As Long
Dim pt As POINTAPI
GetCursorPos pt '取得鼠标坐标信息
hwnd = WindowFromPoint(p.x, p.y) '获取句柄
Label1.Caption = " 当前指向窗口句柄: " & hwnd & ""
Label3.Caption = "X坐标: " & p.x & " ,Y坐标:" & p.y & ""
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询