可以用CreateMutex,在*.dpr里增加以下代码:
program MyProgram;
uses
Forms,
Dialogs,
Windows,
SysUtils,
main in ''main.pas'' {Form1},
{$R *.RES}
var hMutex:HWND;
begin
Application.Initialize;
Application.Title := ''My Program'';
hMutex:=CreateMutex(nil,false,''My Program'');
if GetLastError<>ERROR_ALREADY_EXISTS then
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
begin
MessageDlg(''程序已经运行!'',mtInformation,[mbOK],0);
ReleaseMutex(hMutex);
end;
end.
◆◆
评论读取中....
请登录后再发表评论!
◆◆
修改失败,请稍后尝试