改一下原来的程序就行吧——
var
MyProcessId, PrvId: DWORD;//new
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FThreadEntry32: TThreadEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
FThreadEntry32.dwSize := Sizeof(FThreadEntry32);
ContinueLoop := Thread32First(FSnapshotHandle,FThreadEntry32);
GetWindowThreadProcessId(Handle, @MyProcessId);//new
PrvId := FThreadEntry32.th32OwnerProcessID;//new
while ContinueLoopdo
begin
//线程相关信息在结构TThreadEntry32中
ContinueLoop := Thread32Next(FSnapshotHandle,FThreadEntry32);
if FThreadEntry32.th32OwnerProcessID = MyProcessId then
Break;//new
PrvId := FThreadEntry32.th32OwnerProcessID;//new
end;
CloseHandle(FSnapshotHandle);//new
ShowMessage(Format('Previous ProcessId is: %x', [PrvId]));//new
end;
不过你说“在另一个进程中”不知道什么意思?