Function GetTidByPid(dwProcessId : Integer) : String
Var hSnap : Thandle;
Thread32 : THREADENTRY32;
LoopFlag : Boolean ;
begin
hSnap := CreateToolHelp32SnapShot(TH32CS_SNAPTHREAD ,0);
Thread32.dwSize := Sizeof(Thread32);
if hSnap = INVALID_HANDLE_VALUE then
Begin
Result := 'NotFound' ;
Exit;
End;
//判断一下
LoopFlag := Thread32First(hSnap,Thread32);
if LoopFlag = False then
Begin
Result := 'NotFound';
Exit;
End;
//判断一下
While LoopFlag do
begin
If dwProcessID = Thread32.th32OwnerProcessID then
Begin
Result := Inttostr(Thread32.th32ThreadID) ;
Exit; //根据楼主的意思,得到该进程的第一条线程就直行了
End;
LoopFlag := Thread32Next(hSnap,Thread32);
end;
CloseHandle(hSnap);