VB 已知类名或已知进程名 枚举出所有窗口句柄保存到数组nhwnd

来源:百度知道 编辑:UC知道 时间:2024/06/04 03:16:50
VB 已知类名或已知进程名 枚举出所有窗口句柄保存到数组nhwnd
将满足条件的窗口句柄保存到数组nhwnd,然后将所有句柄和其标题 显示在 用户控件(不是窗体) 的list1里

通过进程PID枚举 相关窗口句柄

Private Sub Command1_Click()
List1.Clear
Find_Window Val(Text1.Text)
End Sub

Private Sub Form_Load()
Text1.Text = ""
Command1.Caption = "枚举窗口"
End Sub

模块代码如下
Option Explicit
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId 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
Dim IfPid As Long
Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim Pid1 As Long
Dim wText As String * 255
GetWindowThreadProcessId hwnd, Pid1
If IfPid = Pid1 Then
GetWindowText hwnd, wText, 100