高分紧急求助:运行一个程序前判断该程序是否已经运行,如果运行则不再运行!怎样判断??
var
hmutex:hwnd;
ret:integer;
begin
Application.Initialize;
hmutex:=createmutex(nil,false,project1);
ret:=getlasterror;
if ret<>error_already_exists then
begin
Application.CreateForm(TForm1, Form1);
end
else
begin
messagedlg(程序已运行。,mtinformation,[mbok],0);
releasemutex(hmutex);
end;
program Project1;
uses
Forms,
Windows,
Unit1 in Unit1.pas {Form1};
{$R *.res}
var
hMutex:hWnd;
begin
Application.Initialize;
Application.Title:=test;
hMutex:=CreateMutex(nil,false,test);
if GetLastError<>Error_Already_Exists then
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
begin
Application.MessageBox(本程序只允许同时运行一个,Error);
ReleaseMutex(hMutex);
end;
end.