1. 如何改“打开”,“另存为” 那个对话框的标题?
2. 我在保存的时候,可能会有多种文件格式,如:
static char BASED_CODE szFilter[] = 
"Iges Files (*.igs;*.iges)|*.igs; *.iges|STEP Files (*.stp;*.step)|*.stp; *step||";
我先用了
CString exportFileName;
if(m_currentFileShortName.GetLength() != 0)
{
  int ipos = m_currentFileShortName.ReverseFind('.');
  exportFileName = m_currentFileShortName.Left(ipos);
}
得到当前文档类处理的文件名,不含路径及扩展名
下面我想让它在“另存为”的对话框里显示为:
当我选择(也是默认选择)Iges Files (*.igs;*.iges)时,显示aa.igs,
当我切换到STEP Files (*.stp;*.step)时自动变化到aa.stp
这个如何实现。

解决方案 »

  1.   

    是不是必须要重载CFileDialog,如果是,那应该怎样重载,重载实现哪些函数呢?
          ~~~~
      

  2.   

    static char szFilter[] = "试验报告文件(*.doc)|*.doc||";
    void CSiFangView::OnFileSave() 
    {
      CSaveDlg dlg(
    FALSE, //TRUE=File Open, FALSE=File Save As
    _T(".doc"), //default filename extension
    "", //initial filename in edit box
    // functionality flags
    // OFN_ALLOWMULTISELECT|  //allow multiple files to be selected
    // OFN_CREATEPROMPT | // if File Save As, prompts user if they want to create non-existant file
    OFN_OVERWRITEPROMPT | // if File Save As--prompts user to ask if they want to overwrite an existing file
    // OFN_ENABLESIZING |   // if Windows NT 5.0 or Win 98, causes box to be resizable by user
    OFN_EXTENSIONDIFFERENT| // allows user to enter a filename with a different extension from the default
    // OFN_FILEMUSTEXIST  // file must exist
    // OFN_NOLONGNAMES | // causes dialog to use short filenames (8.3)
    // OFN_PATHMUSTEXIST | // user can only type valid paths and filenames
    // OFN_NOVALIDATE | // the returned filname can have invalid characters
    // appearence flags
    OFN_HIDEREADONLY | // hides read-only check box
    // OFN_NONETWORKBUTTON | // hides Network button
    // OFN_READONLY | // initially check Read Only check box
    // OFN_SHOWHELP | // Help button appears--when clicked the hook procedure gets a CDN_HELP message
    // custom template flags
    OFN_ENABLETEMPLATE |  // you will be supplying your own custom dialog box template
    0,
    szFilter, //file filter
    NULL); // parent window // set an initial directory
    dlg.m_ofn.lpstrInitialDir = m_sInitDirData; //set the dialog's title
    char lpszTitle[]={"保存参数数据"};
    dlg.m_ofn.lpstrTitle=lpszTitle; // retain the customer's last file filter selection
    dlg.m_ofn.nMaxCustFilter=255; // if OFN_ENABLETEMPLATE is set, define the custom dialog template here
    dlg.m_ofn.lpTemplateName=MAKEINTRESOURCE(IDD_SAVE_DLG);//IDD_WZD_FILEOPEN);
      

  3.   

    第一个问题解决了,但第二个我还是不明白。楼上的意思是重载一个对话框类。然后在打开时做如下调用。但是这个类的结构如何还请赐教。不知我问题陈述的清楚否,大意上是这样,程序现在打开的是一个文件,比放叫aa.sat,文件名我已经放在了文档类的一个类成员里(m_currentFileShortName不含路径).我点另存为弹出对话框,可以选择多种格式,这时默认的保存文件名应该为aa.igs,当我切换到下一种格式时,又变成aa.stp,如此反复。点保存时按照所选的格式及文件名保存。
      

  4.   

    好好看一下MSDN中的参数吧!这种应该不用重载了!
      

  5.   

    CString CStep3::FileOpen()
    {
    OPENFILENAME ofn ;
    TCHAR  szFullName[_MAX_PATH];
    ::ZeroMemory (&ofn, sizeof(OPENFILENAME)) ;
    szFullName[0] = TEXT('\0') ;
    ofn.lStructSize       = sizeof (OPENFILENAME) ;
        ofn.hwndOwner         = m_hWnd;
        ofn.hInstance         = NULL ;
        ofn.lpstrFilter       = "exe 文件\0;*.EXE\0";
        ofn.lpstrCustomFilter = NULL ;
        ofn.nMaxCustFilter    = 0 ;
        ofn.nFilterIndex      = 0 ;
        ofn.nMaxFile          = MAX_PATH ;
        ofn.nMaxFileTitle     = MAX_PATH ;
        ofn.lpstrInitialDir   = "c:\\" ;
        ofn.lpstrTitle        = "保存到";
    ofn.lpstrFile   = szFullName ;
        ofn.nFileExtension    = 0 ;
        ofn.lpstrDefExt       = TEXT("exe") ;
        ofn.lCustData         = 0 ;
        ofn.lpfnHook          = NULL ;
        ofn.lpTemplateName    = NULL ;
        ofn.Flags             = OFN_ENABLESIZING | OFN_OVERWRITEPROMPT ;

    if(!GetOpenFileName(&ofn))
    return "";
    else
    return    ofn.lpstrFile;
    }
      

  6.   

    CString CStep3::FileOpen()
    {
    OPENFILENAME ofn ;
    TCHAR  szFullName[_MAX_PATH];
    ::ZeroMemory (&ofn, sizeof(OPENFILENAME)) ;
    szFullName[0] = TEXT('\0') ;
    ofn.lStructSize       = sizeof (OPENFILENAME) ;
        ofn.hwndOwner         = m_hWnd;
        ofn.hInstance         = NULL ;
        ofn.lpstrFilter       = "exe 文件\0;*.EXE\0";
        ofn.lpstrCustomFilter = NULL ;
        ofn.nMaxCustFilter    = 0 ;
        ofn.nFilterIndex      = 0 ;
        ofn.nMaxFile          = MAX_PATH ;
        ofn.nMaxFileTitle     = MAX_PATH ;
        ofn.lpstrInitialDir   = "c:\\" ;
        ofn.lpstrTitle        = "保存到";
    ofn.lpstrFile   = szFullName ;
        ofn.nFileExtension    = 0 ;
        ofn.lpstrDefExt       = TEXT("exe") ;
        ofn.lCustData         = 0 ;
        ofn.lpfnHook          = NULL ;
        ofn.lpTemplateName    = NULL ;
        ofn.Flags             = OFN_ENABLESIZING | OFN_OVERWRITEPROMPT ;

    if(!GetOpenFileName(&ofn))
    return "";
    else
    return    ofn.lpstrFile;
    }
      

  7.   

    看来还是我没说清楚,呵呵。
    另存为对话框有
    文件名:编辑框
    文件类型:这是一个下拉框,可选保存为若干种文件格式。我的问题是:让当前的文件在文件名的编辑框里以文件类型的扩展名形式显示,如aa.igs 
    当切换到下一种类型时,它就变成aa.stp,以此类推。要求在文件名编辑框里就可以显示带扩展名的文件名,而且随类型切换而变化。可以参照ACDSee的“另存为”这下说明白了吗?
      

  8.   

    MFC Library Reference   CFileDialog::OnTypeChange See Also
    CFileDialog Overview | Class Members | Hierarchy Chart | CFileDialog::OnFileChange
    Override this function to handle the WM_NOTIFY CDN_TYPECHANGE messagesend CDM_SETCONTROLTEXT to the dialog.Command what is yours
    Conquer what is not
      

  9.   

    arpoul(笼中鸟) :你的意思偶明白,偶也碰到过这个问题。先以为修改一下哪或是怎么着重载一下那来实现,但是翻了MSDN没翻到,干脆自己实现 SaveAs,在里面自己实现 Save 对话框。
      

  10.   

    我搞定了,网上找了一个类,实现方法大意与jiangsheng(蒋晟.Net) 说的类似,就是从CFileDialog类中派生了一个类,重载了OnTypeChange方法,还有一些字符串的处理就可以了。代码比较长,如果有人要的请留mail。多谢大家。
      

  11.   

    我的mail是[email protected],需要源码的给我发mail,结贴了