VB如何鼠标经过某程序获取标题名
3个回答
展开全部
Private Type POINTAPI
X As Long
Y As Long
End Type
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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim strText As String * 256
Dim p As POINTAPI
GetCursorPos p '取鼠标所在位置坐标
hwnd1 = WindowFromPoint(p.X, p.Y) '获得鼠标所在位置窗口句柄
Call GetWindowText(hwnd1, strText, 256)
Label1.Caption = hwnd1 '标签一显示句柄
Label2.Caption = Left$(strText, InStr(1, strText, Chr(0)) - 1) '标签二显示标题
End Sub
控件:label1,label2,timer1,command1。
X As Long
Y As Long
End Type
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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim strText As String * 256
Dim p As POINTAPI
GetCursorPos p '取鼠标所在位置坐标
hwnd1 = WindowFromPoint(p.X, p.Y) '获得鼠标所在位置窗口句柄
Call GetWindowText(hwnd1, strText, 256)
Label1.Caption = hwnd1 '标签一显示句柄
Label2.Caption = Left$(strText, InStr(1, strText, Chr(0)) - 1) '标签二显示标题
End Sub
控件:label1,label2,timer1,command1。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询