主页 > 编程资料 > Delphi >
发布时间:2015-09-22 作者:网络 阅读:79次

1。在工程单元中引用windows单元。

2。定义一个变量,类型为hMutex:THandle.

3. hMutex := CreateMutex(nil, False, 'TheStandard',',',');

4.if GetLastError = ERROR_ALREADY_EXISTS then
begin

   CloseHandle(hMutex,',',');
    ShowMessage('本软件的另一个副本已经在运行中',',',');
    application.Terminate;
end
else
begin
Application.CreateForm(TForm1, Form1,',',');
Application.Run;
end;

例如:

program Project1;

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

{$R *.res}
var
hMutex: THandle;
begin
Application.Initialize;
hMutex := CreateMutex(nil, False, 'TheStandard',',',');
if GetLastError = ERROR_ALREADY_EXISTS then
begin

    CloseHandle(hMutex,',',');
    ShowMessage('本软件的另一个副本已经在运行中',',',');
    application.Terminate;
end
else
begin
Application.CreateForm(TForm1, Form1,',',');
Application.Run;
end;
end.

例如:


关键字词: