//声明: GetWindowThreadProcessId(
hWnd: HWND; {指定窗口句柄} lpdwProcessId: Pointer = nil {返回进程 ID 的指针} ):DWORD; {返回线程 ID} 第二个参数@变量获得进程ID,nil函数返回线程ID
procedure TForm1.FormCreate(Sender: TObject); var c: Cardinal; begin GetWindowThreadProcessId(Handle, @c); ShowMessage(IntToStr(c)); {2792; 随机的} {在本例中相同于 GetCurrentProcessID 的结果} c := GetCurrentProcessID; ShowMessage(IntToStr(c)); {2792} c := GetWindowThreadProcessId(Handle, nil); ShowMessage(IntToStr(c)); {2748} {在本例中相同于 GetCurrentThreadID 的结果} c := GetCurrentThreadID; ShowMessage(IntToStr(c)); {2748} end; end.