WinAPI:GetWindowThreadProcessId-指定したウィンドウのプロセスIDまたはスレッドIDを取得する

1235 ワード

//  :
GetWindowThreadProcessId(
  hWnd: HWND;                  {      }
  lpdwProcessId: Pointer = nil {     ID    }
): DWORD;                      {     ID}

 
 
 
 
 

 

 
  

//  :
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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.