假若已经有一个程序app.exe在运行
当我再次运行app.exe时,内存中则会出现二个app.exe
请问如何做才能使我运行第二个app.exe时,
自动将第一个app.exe激活,并将第二个app.exe关闭!
谢谢!

解决方案 »

  1.   

    我代码中的一段
    ...
    {$R *.res}
    begin
    CreateMutex(nil, True, 'Tform1');
      if GetLastError = ERROR_ALREADY_EXISTS then
      begin
      MessageBox(0, '程序正在运行!', '警告!' ,MB_ICONERROR);
     //showwindow(你的程序),自己写吧!//
      Halt;
      end;
      Application.Initialize;
      qd:=Tqd.Create(application);
      qd.Show;
      qd.AlphaBlend:=true;
      qd.Update;
      Application.Title := '铁通电源监控系统';
      Application.CreateForm(Ttietongdb, tietongdb);
      Application.CreateForm(TForm1, Form1);
       while qd.AlphaBlendValue > 15 do
        qd.AlphaBlendValue := qd.AlphaBlendValue - 5; 
      qd.Hide;
      qd.Free;
      Application.Run;
    end.
      

  2.   

    const mypro='tmainapp';//窗体名
     var handle:integer;
    begin
      handle:=findwindow(mypro,nil);
      if handle<>0 then
       begin
        messagebox(0,'程序正在运行,请关闭','警告',0);
        halt;
       end;
    搞定
      

  3.   

    用findWindow好像不行,
    不管app.exe有没有在内存运行,handle每次都返回0