创建互斥对象
program AIMQuery;
uses
Vcl.Forms,
Winapi.Windows,
UnitAIM in 'UnitAIM.pas' {Form1};
{$R *.res}
var
hAppMutex:THandle;
begin
Application.Initialize;
hAppMutex:=CreateMutex(nil,False,PChar('OnlyOne'));
if (hAppMutex=0) then begin
MessageBox(0,PChar('創建互斥對象!'),PChar('Error'),MB_OK+MB_ICONINFORMATION);
Exit;
end;
if (hAppMutex<>0) and (GetLastError()=ERROR_ALREADY_EXISTS) then begin
MessageBox(0,PChar('您已經不是第一次運行該程式了!'),Pchar('Error'),MB_OK+MB_ICONINFORMATION);
CloseHandle(hAppMutex);
Exit;
end;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
创建互斥对象笔记
只是做个笔记而已