我查了一下,前面的贴子,并且拭了一下,下面代码可以实现 Mutex := CreateMutex(nil, true, 'Tet'); if GetLastError <> ERROR_ALREADY_EXISTS then begin Application.Initialize; Application.CreateForm(TFormMain, FormMain); Application.Run; end else MessageBox(0, '已经正在运行!', '请注意......', 48); ReleaseMutex(Mutex);
program Project1;uses windows, dialogs, forms, Unit1 in 'Unit1.pas' {Form1};{$R *.res} var handle:Thandle; begin handle:=findwindow('Tform1','Form1'); if handle=0 then begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end else messagedlg('不能运行该程序的多个势力',mtinformation,[mbok],0); setforegroundwindow(handle); end.
先注册一个互斥变量,然后WAITFORSINGLE,你在这里搜索应该可以找到答案
if GetLastError <> ERROR_ALREADY_EXISTS then
begin
Application.Initialize;
Application.CreateForm(TFormMain, FormMain);
Application.Run;
end
else
MessageBox(0, '已经正在运行!', '请注意......', 48);
ReleaseMutex(Mutex);
windows,
dialogs,
forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}
var
handle:Thandle;
begin
handle:=findwindow('Tform1','Form1');
if handle=0 then
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
messagedlg('不能运行该程序的多个势力',mtinformation,[mbok],0);
setforegroundwindow(handle);
end.