⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitgetthreadpriority.pas

📁 Delphi Win32核心API参考光盘源码 本书包含了常用的Windows API函数
💻 PAS
字号:
unit UnitGetThreadPriority;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Button2: TButton;
    RadioGroup1: TRadioGroup;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  ThreadPriority: Integer;   // holds the thread priority level
begin
  {retrieve the thread priority}
  ThreadPriority := GetThreadPriority(GetCurrentThread);

  {display the thread priority}
  case (ThreadPriority) OF
    THREAD_PRIORITY_LOWEST        : Edit1.Text :=
                                    'THREAD_PRIORITY_LOWEST (-2 to base)';
    THREAD_PRIORITY_BELOW_NORMAL  : Edit1.Text :=
                                    'THREAD_PRIORITY_BELOW_NORMAL (-1 to base)';
    THREAD_PRIORITY_NORMAL        : Edit1.Text :=
                                    'THREAD_PRIORITY_NORMAL (0 to base)';
    THREAD_PRIORITY_HIGHEST       : Edit1.Text :=
                                    'THREAD_PRIORITY_HIGHEST (+2 to base)';
    THREAD_PRIORITY_ABOVE_NORMAL  : Edit1.Text :=
                                    'THREAD_PRIORITY_ABOVE_NORMAL (+1 to base)';
    THREAD_PRIORITY_ERROR_RETURN  : Edit1.Text :=
                                    'THREAD_PRIORITY_ERROR_RETURN';
    THREAD_PRIORITY_TIME_CRITICAL : Edit1.Text :=
                                    'THREAD_PRIORITY_TIME_CRITICAL (base 15)';
    THREAD_PRIORITY_IDLE          : Edit1.Text :=
                                    'THREAD_PRIORITY_IDLE (base set to one)';
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  ThreadHandle: THandle;   // holds the current thread handle
begin
  {retrieve the current thread}
  ThreadHandle := GetCurrentThread;

  {set the selected priority}
  case RadioGroup1.ItemIndex of
    0: SetThreadPriority(ThreadHandle, THREAD_PRIORITY_LOWEST);
    1: SetThreadPriority(ThreadHandle, THREAD_PRIORITY_BELOW_NORMAL);
    2: SetThreadPriority(ThreadHandle, THREAD_PRIORITY_NORMAL);
    3: SetThreadPriority(ThreadHandle, THREAD_PRIORITY_HIGHEST);
    4: SetThreadPriority(ThreadHandle, THREAD_PRIORITY_HIGHEST);
    5: SetThreadPriority(ThreadHandle, THREAD_PRIORITY_TIME_CRITICAL);
    6: SetThreadPriority(ThreadHandle, THREAD_PRIORITY_IDLE);
  end;
end;

end.





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -