vb 通过窗口标题获取对应进程的所有线程失败 求高手解答原因或给一份可用代码 50

模块代码PublicDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsSt... 模块代码
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
'Public Declare Function Thread32First Lib "kernel32" (ByVal hSnapshot As Long, lpte As PROCESSENTRY32) As Boolean
'Public Declare Function Thread32Next Lib "kernel32" (ByVal hSnapshot As Long, lpte As PROCESSENTRY32) As Boolean
Public Declare Function Thread32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As THREADENTRY32) As Boolean
Public Declare Function Thread32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As THREADENTRY32) As Boolean
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Type THREADENTRY32
dwsize As Long
cntusage As Long
th32threadID As Long '线程ID
th32OwnerProcessID As Long '对比这个值是否为指定进程的PID
tpBasePri As Long
tpDeltaPri As Long
dwFlags As Long
End Type

Public ThreadInfo As THREADENTRY32
Public MySnapHandle As Long

部分窗体代码
Hwnds = FindWindow(vbNullString, Text1.Text)
If Hwnds <> 0 Then
Call GetWindowThreadProcessId(Hwnds, PID)
If PID <> 0 Then
MySnapHandle = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0)
If MySnapHandle <> 0 Then
ThreadInfo.dwsize = Len(ThreadInfo)
Call Thread32First(MySnapHandle, ThreadInfo)
Do
If ThreadInfo.th32OwnerProcessID = PID Then
List1.AddItem ThreadInfo.th32threadID
End If
Loop While Thread32Next(MySnapHandle, ThreadInfo) <> 0
Call CloseHandle(MySnapHandle)
End If
End If
End If
text1.text存着窗口标题 到最后list1中只会出现一个0 测试好像是因为Thread32First失败
展开
 我来答
tianqing20wen

2016-06-29 · TA获得超过2.4万个赞
知道大有可为答主
回答量:8226
采纳率:88%
帮助的人:5101万
展开全部

xp win7 测试有效

追问
这个是我发的代码么
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式