runoncep.dpr

来自「Delphi Win32核心API参考光盘源码 本书包含了常用的Windows」· DPR 代码 · 共 34 行

DPR
34
字号
program RunOnceP;

uses
  Forms,
  Windows,
  Dialogs,
  RunOnceU in 'RunOnceU.pas' {Form1};

{$R *.res}

var
  MutexHandle: Integer;

begin
  {attempt to open a handle to the mutex. if this function is successful,
   we know that the application has already started, and we can terminate}
  if OpenMutex(MUTEX_ALL_ACCESS, FALSE, 'RunOnceMutex') <> 0 then
  begin
    ShowMessage('This application is already open!');
    Exit;
  end;

  {if we get here, we are the first instance of this application, so
   create the mutex and immediately acquire ownership of it}
  MutexHandle := CreateMutex(nil, TRUE, 'RunOnceMutex');

  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;

  {now that we are done, we must release the mutex}
  ReleaseMutex(MutexHandle);
end.

⌨️ 快捷键说明

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