Skip to content

Instantly share code, notes, and snippets.

@owlsperspective
Created August 12, 2013 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owlsperspective/6209436 to your computer and use it in GitHub Desktop.
Save owlsperspective/6209436 to your computer and use it in GitHub Desktop.
優先順位クラスを指定してプロセスを起動する
// Delphi 2007 and XE3
// Create form 'TForm1', place 1 Edit, 1 ComboBox, 1 Button.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{$WARN SYMBOL_PLATFORM OFF}
{$IF RTLVersion < 24}
const
BELOW_NORMAL_PRIORITY_CLASS = $00004000;
{$EXTERNALSYM ABOVE_NORMAL_PRIORITY_CLASS}
ABOVE_NORMAL_PRIORITY_CLASS = $00008000;
{$EXTERNALSYM ABOVE_NORMAL_PRIORITY_CLASS}
{$IFEND}
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text := '%windir%\notepad.exe';
with ComboBox1.Items do
begin
BeginUpdate;
try
Clear;
AddObject(Format('%s (0x%8.8X)',['IDLE',IDLE_PRIORITY_CLASS]),
TObject(IDLE_PRIORITY_CLASS));
AddObject(Format('%s (0x%8.8X)',['BELOW_NORMAL',BELOW_NORMAL_PRIORITY_CLASS]),
TObject(BELOW_NORMAL_PRIORITY_CLASS));
AddObject(Format('%s (0x%8.8X)',['NORMAL',NORMAL_PRIORITY_CLASS]),
TObject(NORMAL_PRIORITY_CLASS));
AddObject(Format('%s (0x%8.8X)',['ABOVE_NORMAL',ABOVE_NORMAL_PRIORITY_CLASS]),
TObject(ABOVE_NORMAL_PRIORITY_CLASS));
AddObject(Format('%s (0x%8.8X)',['HIGH',HIGH_PRIORITY_CLASS]),
TObject(HIGH_PRIORITY_CLASS));
AddObject(Format('%s (0x%8.8X)',['REALTIME',REALTIME_PRIORITY_CLASS]),
TObject(REALTIME_PRIORITY_CLASS));
finally
EndUpdate;
end;
end;
with ComboBox1 do
begin
ItemIndex := Items.IndexOfObject(TObject(NORMAL_PRIORITY_CLASS));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ApplicationName: String;
CreationFlags: DWORD;
StartupInfo: TStartupInfo;
ProcessInformation: TProcessInformation;
Length: Integer;
begin
Length := ExpandEnvironmentStrings(PChar(Edit1.Text),nil,0);
SetLength(ApplicationName,Length);
ExpandEnvironmentStrings(PChar(Edit1.Text),PChar(ApplicationName),Length);
UniqueString(ApplicationName);
with ComboBox1 do
begin
if ItemIndex < 0 then
begin
Exit;
end;
CreationFlags := DWORD(Items.Objects[ItemIndex]);
end;
FillChar(StartupInfo,SizeOf(StartupInfo),0);
StartupInfo.cb := SizeOf(StartupInfo);
FillChar(ProcessInformation,SizeOf(ProcessInformation),0);
Win32Check(CreateProcess(PChar(ApplicationName),nil,nil,nil,False,
CreationFlags,nil,nil,StartupInfo,ProcessInformation));
CloseHandle(ProcessInformation.hProcess);
CloseHandle(ProcessInformation.hThread);
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment