您的位置:首页 > 其它

WinAPI: GetWindowThreadProcessId - 获取指定窗口的进程 ID 或线程 ID

2008-03-10 11:59 525 查看
//声明:
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐