请指导:VC中文件操作(Open,save, save as)对话框(common dialog box)的添加?

解决方案 »

  1.   

    // szFilters is a text string that includes two file name filters:
       // "*.my" for "MyType Files" and "*.*' for "All Files."
       char szFilters[]=
          "MyType Files (*.my)|*.my|All Files (*.*)|*.*||";   // Create an Open dialog; the default file name extension is ".my".
       CFileDialog fileDlg (TRUE, "my", "*.my",
          OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
       
       // Display the file dialog. When user clicks OK, fileDlg.DoModal() 
       // returns IDOK.
       if( fileDlg.DoModal ()==IDOK )
       {
          CString pathName = fileDlg.GetPathName();
       
          // Implement opening and reading file in here.
          ...
          //Change the window's title to the opened file's title.
          CString fileName = fileDlg.GetFileTitle ();
      }
    其中
    CFileDialog fileDlg (TRUE,...);//这个TRUE改为FALSE时就是保存
      

  2.   

    CFileDialog的参数:CFileDialog(BOOL bOpenFileDialog,LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL,DWORD dwFlags =   OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,   LPCTSTR lpszFilter = NULL,CWnd* pParentWnd = NULL);参数bOpenFileDialg    如果为TRUE, 则创建文件打开对话框;如果为FALSE,则构造一个File Save As(另存为)对话框。lpszDefExt     缺省文件扩展名,如果用户在文件名编辑框中不包含扩展名,则lpszDefExt定义的扩展名自动加到文件名后。如果为NULL,则不添加扩展名。lpszFileName    初始显示于文件名编辑框中的文件名,如果为NULL,则不显示初始文件名。dwFlags一个或多个标志的组合,使你可定制对话框。要了解这些标志的描述,可参阅联机文档“Win32 SDK”中的OPENFILENAME结构。如果你改变m_ofn.Flags结构成员,在改变中用OR操作保持缺省行为完整。lpszFilter      一列字符串对,指定可以应用到文件的过滤器。如果指定过滤器,仅被选择的文件显示于文件列表框中。pParentWnd       指向文件对话框对象的父窗口或拥有者窗口。
      

  3.   

    追问,Common Dialog Box 是自定义的,如何处理?
      

  4.   

    定制?http://www.vckbase.com/code/downcode.asp?id=1619