最好是有所提示

解决方案 »

  1.   

    你说的不是很清除。
    有很多的办法
    你可以做一个自己定义一个全局变量,程序执行到那时赋值给false,
    而当下一次使用时判断,这个变量是否为Fasle .就可以了。
      

  2.   

    在dpr里uses Windows,
    begin
      //程序只运行一次
      CreateMutex(Nil, true, 'DGEKDsswW');//创建一个标记
      if GetLastError <> ERROR_ALREADY_EXISTS then
      begin
      Application.Initialize;
      //……Form窗体的创建
      Application.Run;
      end
      else
       //自己的提示
    end.
      

  3.   

    :zhuan:var
      hMutex : Thandle;
      WaitResult : word;
      BroadcastList : DWORD;
    begin
         MessageID := RegisterWindowMessage('Check For Choice Previous Inst');
    // register a message to use later on
         hMutex := createMutex(nil,false,pchar('App_Choice')); // grab a mutex
    handle
         WaitResult := WaitForSingleObject(hMutex,10); // wait to see
    if we can have exclusive use of the mutex
         if ( waitResult = WAIT_TIMEOUT ) then // if we can't then broadcast
    the message to make the owner of the mutex respond     { request that the running application takes focus }
           begin
              BroadcastList := BSM_APPLICATIONS;
              BroadcastSystemMessage(
    BSF_POSTMESSAGE,@BroadcastList,MessageID,0,0); //32 bit - broadcast the
    message to all apps - only a prev inst will hear it.
           end
         else
          begin
          { do the normal stuff}
          Application.Title := 'Choice Organics Purchase & Sales System';
          Application.CreateForm(TMainForm, MainForm);
          Application.Run;
          ReleaseMutex(hMutex); // release the mutex as a politeness      end;
          CloseHandle(hMutex); // close the mutex handle
    end.This goes in the MainFormprocedure Tmainform.OnAppMessage(var Msg : TMsg ; Var Handled : Boolean);
    begin
    { If it's the special message then focus on this window}
    if Msg.Message = MessageID then // if we get the broadcast message from an
    another instance of this app that is trying to start up
       begin
          show;
          WindowState := wsMaximized;
          BringToFront;
          SetFocus;
          Handled := true;   end;
    end;//And this goes in the TMainForm.FormCreate ;-Application.OnMessage:= OnAppMessage;
      

  4.   

    另外一种方法
    在工程文件中const classname='TfmMainMMS'; {声明为主窗体的类名}
    var handle:integer; {变量}begin
      handle:=findwindow(classname,nil);{查找是否有此类的窗体}
       if handle<>0 then {不为0则程序已运行}
       begin
         messagebox(0,#13+'  综合市场计算机信息管理系统已经运行!  '+#13,'综合市场',0);{提示程序已运行}
         halt; {退出程序}
       end;
      

  5.   

    请查询一下有关CreateMutex的相关帮助
      

  6.   

    另一法,在工程文件中const classname='TfmMain'; {声明为主窗体的类名}
    var handle:integer; {变量}begin
      handle:=findwindow(classname,nil);{查找是否有此类的窗体}
       if handle<>0 then {不为0则程序已运行}
       begin
         messagebox(0,#13+'  综合市场计算机信息管理系统已经运行!  '+#13,'综合市场',0);{提示程序已运行}
         halt; {退出程序}
       end;  Application.Initialize;
      

  7.   

    program AUTORUN;uses
      Forms,Windows,Messages,
      FRM_AUTORUN in 'FRM_AUTORUN.pas' {LOGO};
      const// 自定义一个消息,用来恢复窗口
      CM_RESTORE=WM_USER+$1000;
      APPNAME='安装程序';
      VAR RvHandle:hWnd;
      {$R *.RES}
    begin
    RvHandle :=FindWindow(APPNAME, NIL); // 根据窗体类名查找窗口句柄
    if RvHandle > 0 then // 如果找到则发送自定义的消息并退出
    begin
         PostMessage(RvHandle,CM_RESTORE,0,0);
         SetForegroundWindow(RvHandle);
         exit;
    end ;
      Application.Initialize;
      Application.Title := '网络版安装引导界面';
      Application.CreateForm(TLOGO, LOGO);
      Application.Run;
    end.
    /////////////////////////////////////////////////////unit FRM_AUTORUN;interfaceuses
        Windows,Forms,jpeg,Controls, StdCtrls, ExtCtrls, Classes,Messages,
        shellapi, SysUtils;
    const// 自定义一个消息,用来恢复窗口
      CM_RESTORE=WM_USER+$1000;
      APPNAME='安装程序';
    type
      TLOGO = class(TForm)
      private
        { Private declarations }  public
        { Public declarations }
        procedure CreateParams(var Params: TCreateParams); override;
        Procedure RestoreRequest(var message: TMessage); message CM_RESTORE ;
      end;var
      LOGO: TLOGO;implementation{$R *.DFM}
    procedure Tlogo.CreateParams(var Params: TCreateParams);
    begin
    // 设置窗体的类名
    inherited CreateParams(Params);
    Params.WinClassName := APPNAME;
    end ;procedure Tlogo.RestoreRequest(var message: TMessage);
    begin
    // 接到自定义的消息后,如果处于最小化状态则恢复,否则放置到桌面的最前面
    //messageBox (Handle , '程序" ' + APPNAME+ ' "已经运行了。' ,'信息' , MB_OK + MB_ICONINFORMATION + MB_SYSTEMMODAL) ;
    if IsIconic(Application.Handle) = TRUE then
    Application.Restore
    else
    Application.BringToFront;
    end;
    end.
    程序运行时会进行“根据窗体类名查找窗口句柄”操作,找到了将那个程序
    设为前台,并关闭自已,
    如没找到,则继续运行。也就是实现一个程序只能运行 一个实例,这是一个基本的向别的程序发消息的例子
      

  8.   

    if IsIconic(Application.Handle) then
              begin
                Application.MainForm.WindowState := wsNormal;
                Application.Restore;
              end;
              SetForegroundWindow(Application.MainForm.Handle);
      

  9.   

    program AUTORUN;uses
      Forms,Windows,Messages,
      FRM_AUTORUN in 'FRM_AUTORUN.pas' {LOGO};
      const// 自定义一个消息,用来恢复窗口
      CM_RESTORE=WM_USER+$1000;
      APPNAME='安装程序';
      VAR RvHandle:hWnd;
      {$R *.RES}
    begin
    RvHandle :=FindWindow(APPNAME, NIL); // 根据窗体类名查找窗口句柄
    if RvHandle > 0 then // 如果找到则发送自定义的消息并退出
    begin
         PostMessage(RvHandle,CM_RESTORE,0,0);
         SetForegroundWindow(RvHandle);
         exit;
    end ;
      Application.Initialize;
      Application.Title := '网络版安装引导界面';
      Application.CreateForm(TLOGO, LOGO);
      Application.Run;
    end.
    /////////////////////////////////////////////////////unit FRM_AUTORUN;interfaceuses
        Windows,Forms,jpeg,Controls, StdCtrls, ExtCtrls, Classes,Messages,
        shellapi, SysUtils;
    const// 自定义一个消息,用来恢复窗口
      CM_RESTORE=WM_USER+$1000;
      APPNAME='安装程序';
    type
      TLOGO = class(TForm)
      private
        { Private declarations }  public
        { Public declarations }
        procedure CreateParams(var Params: TCreateParams); override;
        Procedure RestoreRequest(var message: TMessage); message CM_RESTORE ;
      end;var
      LOGO: TLOGO;implementation{$R *.DFM}
    procedure Tlogo.CreateParams(var Params: TCreateParams);
    begin
    // 设置窗体的类名
    inherited CreateParams(Params);
    Params.WinClassName := APPNAME;
    end ;procedure Tlogo.RestoreRequest(var message: TMessage);
    begin
    // 接到自定义的消息后,如果处于最小化状态则恢复,否则放置到桌面的最前面
    //messageBox (Handle , '程序" ' + APPNAME+ ' "已经运行了。' ,'信息' , MB_OK + MB_ICONINFORMATION + MB_SYSTEMMODAL) ;
    if IsIconic(Application.Handle) = TRUE then
    Application.Restore
    else
    Application.BringToFront;
    end;
    end.
    程序运行时会进行“根据窗体类名查找窗口句柄”操作,找到了将那个程序
    设为前台,并关闭自已,
    如没找到,则继续运行。也就是实现一个程序只能运行 一个实例,这是一个基本的向别的程序发消息的例子
      

  10.   

    这个最简单:
    implementation 
    var hnd: THandle;initialization
        hnd := CreateMutex(nil, True, 'irgendwaseinmaliges');
        if GetLastError = ERROR_ALREADY_EXISTS then Halt;finalization
        if hnd <> 0 then CloseHandle(hnd);
    end.
      

  11.   

    打开:project->view source
    在uses下加window;
    begin
    if(FindWindow(nil,'广东省出口发票管理系统——用户登陆')<>0)then
    //引号里的中文是你程序主界面的caption;
     Application.MessageBox('已经有一个实例','警告',MB_OK)
       else
      begin
      Application.Initialize;
      Application.CreateForm(TDengLuForm1, DengLuForm1);
      Application.CreateForm(TExportform, Exportform);
      Application.CreateForm(TTianKaiForm, TianKaiForm);
      Application.CreateForm(TTongJiForm1, TongJiForm1);
      Application.CreateForm(TCaXunform, CaXunform);
      Application.CreateForm(TKeHuGUanliForm1, KeHuGUanliForm1);
      Application.CreateForm(TCaXunForm1, CaXunForm1);
      Application.CreateForm(Txitongweihuform, xitongweihuform);
      Application.CreateForm(TFaPiaoChaXunForm1, FaPiaoChaXunForm1);
      Application.CreateForm(TQingkuangTongJiForm1, QingkuangTongJiForm1);
      Application.CreateForm(TCopia_Dbf, Copia_Dbf);
      Application.CreateForm(THuiFuform, HuiFuform);
      Application.Run;
      end;
    end;
      

  12.   

    CreateMutex是自已写的;
    var
      Mutex: hWnd;
    function CreateMutex: Boolean;
    var
      PrevInstHandle: THandle;
      AppTitle: PChar;
    begin
      AppTitle := StrAlloc(100);
      StrPCopy(AppTitle, Application.Title);
      Result := True;
      Mutex := Windows.CreateMutex(nil, False, AppTitle);
      if (GetLastError = ERROR_ALREADY_EXISTS) or (Mutex = 0) then begin
        Result := False;
        SetWindowText(Application.Handle, '');
        PrevInstHandle := FindWindow(nil, AppTitle);
        if PrevInstHandle <> 0 then begin
          if IsIconic(PrevInstHandle) then
            ShowWindow(PrevInstHandle, SW_RESTORE)
          else
            BringWindowToTop(PrevInstHandle);
          SetForegroundWindow(PrevInstHandle);
        end;
        if Mutex <> 0 then
          Mutex := 0;
      end;
      StrDispose(AppTitle);
    end;
      

  13.   

    补充:下面的内容不用你输入,是你系统存在的,要加的代码只有上面的一点!
     Application.Initialize;
      Application.CreateForm(TDengLuForm1, DengLuForm1);
      Application.CreateForm(TExportform, Exportform);
      Application.CreateForm(TTianKaiForm, TianKaiForm);
      Application.CreateForm(TTongJiForm1, TongJiForm1);
      Application.CreateForm(TCaXunform, CaXunform);
      Application.CreateForm(TKeHuGUanliForm1, KeHuGUanliForm1);
      Application.CreateForm(TCaXunForm1, CaXunForm1);
      Application.CreateForm(Txitongweihuform, xitongweihuform);
      Application.CreateForm(TFaPiaoChaXunForm1, FaPiaoChaXunForm1);
      Application.CreateForm(TQingkuangTongJiForm1, QingkuangTongJiForm1);
      Application.CreateForm(TCopia_Dbf, Copia_Dbf);
      Application.CreateForm(THuiFuform, HuiFuform);
      Application.Run;
      

  14.   

    《Delphi 5 开发人员指南》中有这个例子。
      

  15.   

    在dpr文件里用互斥实现
    var
       MutexHandle:THandle;
       hPrevInst:Boolean;
    begin
       MutexHandle := CreateMutex(nil, True, 'AppMutex');
      if MutexHandle <> 0 then begin
          if GetLastError= ERROR_ALREADY_EXISTS then begin
             hPrevInst := True;
             CloseHandle(MutexHandle);
             Halt;
          end else begin
             hPrevInst := FALSE;
          end;
       end else begin
         hPrevInst := FALSE;
       end;
    end;
      

  16.   

    shanxia(山峡),用Findwindows不好,无法保证Caption唯一