在DPR文件中加入对程序标题的判断即可!
var
    handle:Hwnd;
begin
  handle:=FindWindow('TApplication','TEST');
  if handle<>0 then
  begin
     postmessage(handle,wm_syscommand,sc_restore,0);
     SetForegroundWindow(handle);
     halt;
  end;
  Application.Initialize;
  Application.Title := 'TEST';

解决方案 »

  1.   

    procedure ClosePrg(TITLENAME:string);var
      HWndOpts : HWnd;begin  HWndOpts := Winprocs.FindWindow(nil, pchar(TITLENAME));
      if HWndOpts <> 0 then
         SendMessage(HWndOpts, WM_CLOSE, 0, 0);
    end;
      

  2.   

    上面的方法只对有窗体的有效!程序创建时调用CreateMutex创建一个Mutex,然后判断该对象是否存在!如:
    program CPUinfo;uses
      Forms,
      windows,
      CPUMain in 'CPUMain.pas' {Main},
      Test in 'Test.pas' {FormTest};{$R *.res}
    var
    hMutex:HWND;
    Ret:Integer;
    begin
      Application.Initialize;
      Application.Title := 'Ehomsoft CPUInfo';
      hMutex:=CreateMutex(nil,False,'Ehomsoft SysInfo');
      Ret:=GetLastError;
      If Ret<>ERROR_ALREADY_EXISTS then
      Begin
      Application.CreateForm(TMain, Main);
      Application.CreateForm(TFormTest, FormTest);
      Application.Run;
      end;
    end.当然方法还有很多!
      

  3.   

    Application.Initialize;
      CreateMutex(nil,false,PChar('www.ddddddd.com'));
      if GetLastError <> ERROR_ALREADY_EXISTS then begin
        Application.CreateForm(TPEEK, PEEK);
        Application.ShowMainForm := false;
        Application.Run;
      end else begin
      //showmessage('fuck');
      Application.Terminate;
      end;