vb中已知进程名称(不知道窗口标题),如何获取其hWnd(句柄)?

来源:百度知道 编辑:UC知道 时间:2024/06/26 01:16:50
如果满意奖励50分.
房恩宏这位朋友的回答网上太多了,不能解决问题啊,我说的是进程名称,不是进程PID.

窗体代码如下 在TEXT输入进程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
For