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

📄 singleinstance.pas

📁 It is a dark time for the Rebellion. Although the Death Star has been destroyed, Imperial troops hav
💻 PAS
字号:
unit SingleInstance;
{
  Single Instance Unit
  by Corbin Dunn
  cdunn@borland.com
  Delphi Developer Support
}

// Only allow one instance of the screen saver to run at a time.
// Windows tends to start multiple copies of the Screen Saver at
// any time.

interface

procedure FreeMutex;

implementation

uses SysUtils, Forms, Windows;

const
  cSWSSString = 'Delphi StarWars Screen Saver';
var
  SingleMutex: THandle = 0;

procedure CreateMutexOrDie;
begin
  if OpenMutex(MUTEX_ALL_ACCESS, False, cSWSSString) = 0 then
  begin
    // First one - the mutex didn't exist, so create it.
    SingleMutex := CreateMutex(nil, False, cSWSSString);
  end
  else
  begin
    // The mutex did exist, so the application is running.
    // Terminate it in this case.
    Application.ShowMainForm := False;
    Application.Terminate;
  end;
end;

procedure FreeMutex;
begin
  if SingleMutex <> 0 then
  begin
    CloseHandle(SingleMutex);
    SingleMutex := 0;
  end;
end;

initialization
  CreateMutexOrDie;
finalization
  FreeMutex;
end.

⌨️ 快捷键说明

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