C\S 通信中,比如 客户端知道要接受 Test.txt 文件,如何才能在客户端 弹出像QQ文件另存为那样的对话框,
来选择接收文件的路径, 默认文件名为原始名字(注:需要在Dll中实现)。哪位兄弟帮忙指点一下,万分感谢!

解决方案 »

  1.   

    拿SaveDialog写两句程序就可以了
      

  2.   

    在DLL添加一个窗体,需要时引用就可以了
      

  3.   

    TOpenDialog,TSaveDialog可以,不过有时候喜欢跑后面,看不到
    unit   OSDialogLib;   
        
      interface   
        
      uses   
          Windows,SysUtils,Dialogs,Forms;   
        
      function   ShowOpenFileDialog(const   DialogPrompt:PChar;   
                                                              const   DefaultFileName:PChar;   
                                                              const   FileFilter:PChar):PChar;   stdcall;   
      function   ShowSaveFileDialog(const   DialogPrompt:PChar;   
                                                              const   DefaultFileName:PChar;   
                                                              const   FileFilter:PChar):PChar;   stdcall;   
        
      implementation   
        
      //显示打开文件对话框   
      function   ShowOpenFileDialog(const   DialogPrompt:PChar;   
                                                              const   DefaultFileName:PChar;   
                                                              const   FileFilter:PChar):PChar;   stdcall;   
      var   
          OpenFileDialog:   TOpenDialog;   
          FileNameA:   String;   
          FileName:   String;   
      begin   
          Result   :=   PChar('');   
          Application.Handle   :=   GetActiveWindow();   
          OpenFileDialog   :=   TOpenDialog.Create(Application);   
          OpenFileDialog.Filter   :=   StrPas(FileFilter);   
          OpenFileDialog.Title   :=   StrPas(DialogPrompt);   
          if   OpenFileDialog.Title   =   ''   then   OpenFileDialog.Title   :=   '打开';   
          //设置路径和文件必须存在   
          OpenFileDialog.Options   :=   OpenFileDialog.Options   +   [ofPathMustExist,   ofFileMustExist];   
          FileNameA   :=   StrPas(DefaultFileName);   
          if   FileNameA   <>   ''   then   OpenFileDialog.FileName   :=   FileNameA;   
        
          if   OpenFileDialog.Execute()   then   
          begin   
              FileName   :=   OpenFileDialog.FileName;   
              if   Pos('nsf',FileName)   <=   0   then   FileName   :=   FileName   +   '.nsf';   
              Result   :=   PChar(FileName);   
              OpenFileDialog.Free;   
          end;   
      end;   
        
      //保存打开文件对话框   
      function   ShowSaveFileDialog(const   DialogPrompt:PChar;   
                                                              const   DefaultFileName:PChar;   
                                                              const   FileFilter:PChar):PChar;   stdcall;   
      var   
          SaveFileDialog:   TSaveDialog;   
          FileNameA:   String;   
          FileName:   String;   
      begin   
          Result   :=   PChar('');   
          Application.Handle   :=   GetActiveWindow();   
          SaveFileDialog   :=   TSaveDialog.Create(Application);   
          SaveFileDialog.Filter   :=   StrPas(FileFilter);   
          SaveFileDialog.Title   :=   StrPas(DialogPrompt);   
          if   SaveFileDialog.Title   =   ''   then   SaveFileDialog.Title   :=   '另存为';   
          //设置提示用户文件已经存在   
          SaveFileDialog.Options   :=   SaveFileDialog.Options   +   [ofOverwritePrompt];   
          FileNameA   :=   StrPas(DefaultFileName);   
          if   FileNameA   <>   ''   then   SaveFileDialog.FileName   :=   FileNameA;   
        
          if   SaveFileDialog.Execute()   then   
          begin   
              FileName   :=   SaveFileDialog.FileName;   
              if   Pos('nsf',FileName)   <=   0   then   FileName   :=   FileName   +   '.nsf';   
              Result   :=   PChar(FileName);   
              SaveFileDialog.Free;   
          end;   
      end;   
        
      end.