delphi 如何判断一个软件是否在运行?
2个回答
展开全部
var
hMutex: Cardinal;
Ret: Integer;
sExeNm:string;
begin
sExeNm:='';
sExeNm := ExtractFileName(Application.ExeName);
if Pos('.', sExeNm) > 0 then
sExeNm := Copy(sExeNm, 1, Pos('.', sExeNm) - 1);
sExeNm:=sExeNm+'_TBYF';
hMutex := CreateMutex(nil, False, PChar(sExeNm));
Ret := GetLastError;
if Ret <> ERROR_ALREADY_EXISTS then
begin
qdck:=Tqdck.Create(Application);
qdck.Show;
qdck.Update;
//ShowWindow(Application.Handle, SW_HIDE);
Application.Initialize;
Application.Title:='三阳医院住院信息记录软件';
Application.CreateForm(Tdm_sjmk, dm_sjmk);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(Tzybrdjb, zybrdjb);
Application.CreateForm(Tbb_bafmdy, bb_bafmdy);
Application.CreateForm(Tdzjsb, dzjsb);
qdck.Free;
Application.Run;
end
else
begin
ReleaseMutex(hMutex);
Application.MessageBox('该程序已经运行,可能已被您最小化!', '重复运行', MB_OK + MB_ICONEXCLAMATION);
Halt;
end;
end.
hMutex: Cardinal;
Ret: Integer;
sExeNm:string;
begin
sExeNm:='';
sExeNm := ExtractFileName(Application.ExeName);
if Pos('.', sExeNm) > 0 then
sExeNm := Copy(sExeNm, 1, Pos('.', sExeNm) - 1);
sExeNm:=sExeNm+'_TBYF';
hMutex := CreateMutex(nil, False, PChar(sExeNm));
Ret := GetLastError;
if Ret <> ERROR_ALREADY_EXISTS then
begin
qdck:=Tqdck.Create(Application);
qdck.Show;
qdck.Update;
//ShowWindow(Application.Handle, SW_HIDE);
Application.Initialize;
Application.Title:='三阳医院住院信息记录软件';
Application.CreateForm(Tdm_sjmk, dm_sjmk);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(Tzybrdjb, zybrdjb);
Application.CreateForm(Tbb_bafmdy, bb_bafmdy);
Application.CreateForm(Tdzjsb, dzjsb);
qdck.Free;
Application.Run;
end
else
begin
ReleaseMutex(hMutex);
Application.MessageBox('该程序已经运行,可能已被您最小化!', '重复运行', MB_OK + MB_ICONEXCLAMATION);
Halt;
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询