我想编写一个主程序,能达到象金山毒霸主程序的效果:
即程序在执行以后,如果我通过桌面快捷方式再次执行它,则程序不重复执行,但是能够把本程序窗口恢复到正常情况且为当前活动窗口。请问如何实现?

解决方案 »

  1.   

    改写program文件var
      mHandle, fHandle: THandle;{$R *.res}begin
      Application.Initialize;
      mHandle := Windows.CreateMutex(nil, true, 'SendMessage');
      if mHandle <> 0 then
      begin
        if GetLastError = Windows.ERROR_ALREADY_EXISTS then
        begin
          fHandle := FindWindow(PChar('TfrmSend'), nil);
          ShowWindow(fHandle, SW_RESTORE);
          SetForeGroundWindow(fHandle);
          Windows.ReleaseMutex(mHandle);
          Halt;
        end;
      end;  Application.CreateForm(TfrmSend, frmSend);
      Application.Run;
    end.