program SSDelphiTest1; {$R 'myresource.res' 'myresource.rc'} uses Vcl.Forms, Unit1 in 'Unit1.pas' {Form1} , Unit2 in 'Unit2.pas' {Form2} , Unit3 in 'Unit3.pas' {Form3} , System.SysUtils, System.StrUtils, Winapi.Windows; {$R *.res} var arg: string; hwnd: Int64; hMutex: THandle; const MUTEXNAME: string = 'SSDelphiTest1Mutex5963'; // 他と被らない文字列にする begin Application.Initialize; Application.MainFormOnTaskbar := True; // コマンドライン第1引数を '/s', '/c', '/p' の状態にする if ParamCount > 0 then arg := ParamStr(1).Substring(0, 2).ToLower else arg := ''; if arg = '/s' then begin // フルスクリーン表示 // 多重起動禁止処理 hMutex := CreateMutex(nil, False, PChar(MUTEXNAME)); if (hMutex = 0) or (GetLastError = ERROR_ALREADY_EXISTS) then begin // 既に起動している if hMutex <> 0 then CloseHandle(hMutex); // ShowMessage('Already running'); Exit; // Exit は他言語での Return みたいなもの end; try begin Application.CreateForm(TForm1, Form1); Application.Run; end; finally if hMutex <> 0 then CloseHandle(hMutex); end; Exit; end; if arg = '/c' then begin // 設定画面表示 Application.CreateForm(TForm2, Form2); Application.Run; Exit; end; if arg = '/p' then begin // プレビュー画面表示 // ウインドウハンドルを取得 if ParamCount >= 2 then hwnd := StrToInt64Def(ParamStr(2), 0) else hwnd := 0; Application.CreateForm(TForm3, Form3); // ウインドウハンドルが渡されていたら親ウインドウを指定 if hwnd <> 0 then Form3.ParentWindow := hwnd; Application.Run; Exit; end; // 設定画面表示 Application.CreateForm(TForm2, Form2); Application.Run; end.