以Save As方式使用CFileDialog时,若不选择已有的文件,而输入一新的不含后缀的文件名后,如何得知目前选择的文件的后缀名?
比如,输入新文件名kk,然后选择文件的后缀名是RTF,但程序中如何得知目前选择的是RTF而不是其他?

解决方案 »

  1.   

    CString GetFileExt( ) const;Return ValueThe extension of the filename.
      

  2.   

    是你在创建CFileDialog时,设定的参数lpszDefExt的值,如果没有设定,则取默认的NULL,那么生成的文件将没有扩展名。或者你设置了lpszFilter,那么将是lpszFilter里设置的值。
    详情请参阅MSDN的CFileDialog类。
      

  3.   

    CFileDialog::GetFileExt 
    CString GetFileExt( ) const;Return ValueThe extension of the filename.ResCall this function to retrieve the extension of the filename entered into the dialog box. For example, if the name of the file entered is DATA.TXT, GetFileExt returns "TXT".If m_ofn.Flags has the OFN_ALLOWMULTISELECT flag set, this string contains a sequence of null-terminated strings, with the first string being the directory path of the file group selected, followed by the names of all files selected by the user. To retrieve file pathnames, use the GetStartPosition and GetNextPathName member functions.
      

  4.   

    我希望的是在运行过程中,可选择不同的文件类型(如: RTF,TXT,DOC等).
    当我选择了不同的问题类型,并输入了一个不含后缀的新文件名
    (如:kk,该文件不存在,还未建立)后,如何把该文件名与当前选择的后缀(如: RTF,TXT,DOC等)连接成一个完整的文件名?
      

  5.   

    CString bb;
    bb="(*.rtf)|*.rtf|(*.txt)|*.txt|(*.doc)|*.doc|";//這是設置可選擇類型
    CFileDialog dlg(FALSE, "rtf", NULL, OFN_OVERWRITEPROMPT,bb);
    //dlg裡面的rtf是設置默認擴展名的
    dlg.DoModal()選擇後.自動會和你當前所選擇的類型結合.並且成為你名稱的后綴.
    if(IDCancle==dlg.DoModal()) return;
    CString aaa;
    aaa=dlg.GetPathName();
    aaa.MakeLower();
    if(csTemp.Right(4)!=".doc")//這裡判斷類型