WinAPI: GetCurrentThread、GetCurrentThreadId、GetCurrentProcess、GetCurrentProcessId

來源:互聯網
上載者:User
{返回當前線程的虛擬控制代碼}GetCurrentThread: THandle;{返回當前線程 ID}GetCurrentThreadId: DWORD;{返回當前進程的虛擬控制代碼}GetCurrentProcess: THandle;{返回當前進程 ID}GetCurrentProcessId: DWORD;

提示:
ID 是系統唯一的標識.
所謂虛擬控制代碼, 就是該控制代碼只在調用進程的進程中有效, 也不能被繼承;
如果用於其他進程需要用 DuplicateHandle 複製控制代碼;
GetCurrentProcess 返回的虛擬控制代碼可以通過 OpenProcess 建立一個真實的控制代碼.

舉例:

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, Grids;type  TForm1 = class(TForm)    StringGrid1: TStringGrid;    procedure FormCreate(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin  StringGrid1.Cells[0,0] := '當前線程虛擬控制代碼: ';  StringGrid1.Cells[0,1] := '當前線程 ID: ';  StringGrid1.Cells[0,2] := '當前進程虛擬控制代碼: ';  StringGrid1.Cells[0,3] := '當前進程 ID: ';  StringGrid1.Cells[1,0] := IntToStr(GetCurrentThread);  StringGrid1.Cells[1,1] := IntToStr(GetCurrentThreadID);  StringGrid1.Cells[1,2] := IntToStr(GetCurrentProcess);  StringGrid1.Cells[1,3] := IntToStr(GetCurrentProcessId);  {下面是顯示格式的調整}  StringGrid1.Align := alClient;  StringGrid1.FixedRows := 0;  StringGrid1.RowCount := 4;  StringGrid1.ColCount := 2;  StringGrid1.ColWidths[0] := StringGrid1.Canvas.TextWidth(StringGrid1.Cells[0,0]) + 4;  StringGrid1.ColWidths[1] := StringGrid1.Canvas.TextWidth(StringGrid1.Cells[0,1]) + 4;end;end.//:


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.