Declare
Function
FindWindowEx
Lib
"user32"
Alias
"FindWindowExA"
(ByVal
hWnd1
As
Long,
ByVal
hWnd2
As
Long,
ByVal
lpsz1
As
String,
ByVal
lpsz2
As
String)
As
Long
'hwnd1是你找到的记事本的窗口句饼
dim
hwnd2
as
long
HWND1
=
FindWindow(vbNullString,
"你好")
hwnd2=
findwindowex(hwnd1,0,vbNullString,"发送")
Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Sub GetHandle() Dim Result As Long Resule = FindWindow(vbNullString, "迅雷看看播放器") '根据窗口标题取得窗体句柄 GetHandle = Result '返回句柄End Sub只是简单写了一下,你可以根据自己的要求改一下
刚才写错了。应该是Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Sub GetHandle() Dim Result As Integer Resule = FindWindow(vbNullString, "迅雷看看播放器") '根据窗口标题取得窗体句柄 GetHandle = Result '返回句柄End Sub
获取句柄不一定要用 FindWindow ,还可以枚举:
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 Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Sub Command1_Click()
Dim lngHwnd As Long, ret As Long
Dim s As String 255
Dim sName As String
lngHwnd = GetWindow(Mehwnd, GW_HWNDFIRST)
Do While lngHwnd
ret = GetWindowText(lngHwnd, s, 255)
sName = Blank(s)
If InStr(sName, "记事本") <> 0 Then '这里“记事本”替换成程序标题相同的部分
'这里写 将句柄加入数组的相关代码
End If
lngHwnd = GetWindow(lngHwnd, GW_HWNDNEXT)
Loop
End Sub
Public Function Blank(ByVal szString As String) As String
Dim l As Integer
l = InStr(szString, Chr(0))
If l > 0 Then
Blank = Left(szString, l - 1)
Else
Blank = szString
End If
End Function
以上就是关于VB只知道父窗口标题如何得到子窗口句柄全部的内容,包括:VB只知道父窗口标题如何得到子窗口句柄、vb怎么取窗口句柄、vb如何获取到窗口的句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)