在VB中,如何通过FindWindow查找已知标题中的一部分文字的窗口的句柄
答案:2 悬赏:30 手机版
解决时间 2021-12-02 22:22
- 提问者网友:星軌
- 2021-12-02 14:15
在VB中,如何通过FindWindow查找已知标题中的一部分文字的窗口的句柄
最佳答案
- 五星知识达人网友:北方的南先生
- 2021-12-02 15:30
您好,您可以参考以下代码:
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
private sub getprocessname()
Dim lngDeskTopHandle As Long
Dim lngHand As Long
Dim strName As String * 255
dim a as long
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
Do While lngHand <> 0
GetWindowText lngHand, strName, Len(strName)
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
If Left$(strName, 1) <> vbNullChar Then
if instr(strname , "123") then
a = FindWindow(vbNullString, CStr(strName))'此处a即所需句柄,您可以在此处中断并获取该句柄,或将句柄数据写入数组以获取所有包含"123"的窗口句柄
end if
End If
Loop如果本次回答对您有帮助,请您采纳以支持我们的发展,谢谢!!
追问GW_CHILD
GW_HWNDNEXT
这2个常量好像没定义,是不是定义了就可以了,我测试不成功,发现的这个问题追答Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
我对我的失误非常抱歉,由此带来的不便,请你理解,谢谢!
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
private sub getprocessname()
Dim lngDeskTopHandle As Long
Dim lngHand As Long
Dim strName As String * 255
dim a as long
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
Do While lngHand <> 0
GetWindowText lngHand, strName, Len(strName)
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
If Left$(strName, 1) <> vbNullChar Then
if instr(strname , "123") then
a = FindWindow(vbNullString, CStr(strName))'此处a即所需句柄,您可以在此处中断并获取该句柄,或将句柄数据写入数组以获取所有包含"123"的窗口句柄
end if
End If
Loop如果本次回答对您有帮助,请您采纳以支持我们的发展,谢谢!!
追问GW_CHILD
GW_HWNDNEXT
这2个常量好像没定义,是不是定义了就可以了,我测试不成功,发现的这个问题追答Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
我对我的失误非常抱歉,由此带来的不便,请你理解,谢谢!
全部回答
- 1楼网友:旧脸谱
- 2021-12-02 15:47
我也不知道怎么搞的我也等待 .
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯