procedure TForm1.Button1Click(Sender: TObject);
begin
if {进程列表里存在程序 "B.exe" } then
{显示出主窗体}
else
begin
ShellExecute(handle, nil,pchar('D:\test.exe'),Nil, Nil, SW_NORMAL);
{显示主窗体}
end
end;
A 程序:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(handle, nil,pchar('D:\test.exe'),Nil, Nil, SW_NORMAL);
end;
B 程序:
if FindWindow(nil,'test') <> 0 then
begin
if Visible = false then
begin
Visible := true;
Application.ShowMainForm := Visible;
SetForegroundWindow(Application.Handle);
ShowWindow(Application.Handle, SW_SHOWNORMAL);
end;
end;