delphi如何实现只运行一个实例,且激活第一个实例中的某个窗体?
只运行一个实例的代码我有了,
begin
Application.Initialize;
//只运行一个程序
hAppMutex := CreateMutex(nil, false, PChar('MantPlan')); //创建互斥对象
if hAppMutex = 0 then
begin
//showmessage('dfdfd');
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('OK'), MB_OK + MB_ICONINFORMATION);
//关闭互斥对象,退出程序
//form2.Show;
closeHandle(hAppMutex);
exit;
end;
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm3, Form3);
Application.CreateForm(TForm4, Form4);
Application.Run;
CloseHandle(hAppMutex); //关闭互斥对象
end.
如何在二次执行这个程序时,激活这个程序已运行的那个实例的某个窗口(如form2)呢?