VB 已知类名或已知进程名 枚举出所有窗口句柄保存到数组nhwnd
将满足条件的窗口句柄保存到数组nhwnd,然后将所有句柄和其标题 显示在 用户控件(不是窗体) 的list1里
VB 已知类名或已知进程名 枚举出所有窗口句柄保存到数组nhwnd
答案:2 悬赏:60 手机版
解决时间 2021-02-18 01:52
- 提问者网友:饥饿走向夜
- 2021-02-17 13:16
最佳答案
- 五星知识达人网友:你哪知我潦倒为你
- 2021-02-17 14:14
通过进程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
Form1.List1.AddItem "句柄:" & hwnd & " 标题:" & wText
End If
EnumWindowsProc = True
End Function
Public Sub Find_Window(ByVal Pid As Long)
IfPid = Pid
EnumWindows AddressOf EnumWindowsProc, 0
End Sub
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
Form1.List1.AddItem "句柄:" & hwnd & " 标题:" & wText
End If
EnumWindowsProc = True
End Function
Public Sub Find_Window(ByVal Pid As Long)
IfPid = Pid
EnumWindows AddressOf EnumWindowsProc, 0
End Sub
全部回答
- 1楼网友:思契十里
- 2021-02-17 15:02
搜一下:VB 已知类名或已知进程名 枚举出所有窗口句柄保存到数组nhwnd
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯