求助“直接调用GetHandle函数,然后传一个窗口标题进去就可以获得其窗口句柄了.”
Option ExplicitPrivate 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 Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Function GetHandle(Title As String) As Long
Dim tmp As String
Dim hwnd As Long
Dim lngProcID As Long
Dim strTitle As String * 255 '//用来存储窗口的标题
'//取得桌面窗口
hwnd = GetDesktopWindow()
'//取得桌面窗口的第一个子窗口
hwnd = GetWindow(hwnd, GW_CHILD)
'//通过循环来枚举所有的窗口
Do While hwnd <> 0
'//取得下一个窗口的标题,并写入到列表框中
GetWindowText hwnd, strTitle, Len(strTitle)
If Left$(strTitle, 1) <> vbNullChar Then
tmp = Left$(strTitle, InStr(1, strTitle, vbNullChar))
If Left(tmp, Len(Title)) = Title Then
GetHandle = hwnd
End If
End If
'//调用GetWindow函数,来取得下一个窗口
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
End Function
求助;怎么“直接调用GetHandle函数?然后传一个窗口标题进去就可以获得其窗口句柄了.”?
希望各位大大给出调用GetHandle函数的完整代码
我学VB一个多月了,还不太懂这些,求好心人帮忙,我会努力学习的。