本帖最后由 lukk123 于 2010-01-22 15:09:28 编辑

解决方案 »

  1.   

    放到工程文件开始,CNT_APPLICATION_NAME是程序窗体标题var
      h: THandle;
      prevInst: THandle;
    begin
      (*******单实例模式*********)
      h := CreateMutex(nil, True, CNT_APPLICATION_NAME);
      if (GetLastError = ERROR_ALREADY_EXISTS) or (h = 0) then
      begin
        prevInst := FindWindow(nil, CNT_APPLICATION_NAME);
        If prevInst<>0 then
              if isiconic(prevInst)then
                 ShowWindow(prevInst,SW_RESTORE)
              ELSE
                 SetForegroundWindow(prevInst);
        Exit;
      end;
      (***********单实例模式*********)
      

  2.   

    是不是这样.好象不行.
    uses
      Forms,Windows,
      Unit1 in 'Unit1.pas' {Form1},
      wdRunOnce in 'wdRunOnce.pas';{$R *.res}var
      h: THandle;
      prevInst: THandle;
    begin  Application.Initialize;
     h := CreateMutex(nil, True, 'Form1');
      if (GetLastError = ERROR_ALREADY_EXISTS) or (h = 0) then
      begin
        prevInst := FindWindow(nil, 'Form1');
        If prevInst<>0 then
              if isiconic(prevInst)then
                 ShowWindow(prevInst,SW_RESTORE)
              ELSE
                 SetForegroundWindow(prevInst);
        Exit;
      end;
      //if not AppHasRun(Application.Handle) then
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.我只是想在现在基础上.不知.怎么.在元件里.激活已经隐藏到托盘和窗体
      

  3.   

      if (GetLastError = ERROR_ALREADY_EXISTS) or (h = 0) then
      begin
        prevInst := FindWindow(nil, 'Form1');
        If prevInst<>0 then
              if isiconic(prevInst)then
                 ShowWindow(prevInst,SW_RESTORE)
              ELSE
                 SetForegroundWindow(prevInst);//改為sendmessage(prevInst,mousemsg,0,0)
        Exit;
      end;