singleinstance.pas
来自「It is a dark time for the Rebellion. Alt」· PAS 代码 · 共 56 行
PAS
56 行
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 + =
减小字号Ctrl + -
显示快捷键?