如何在文件菜单中保存和打开菜单命令中添加.cpp和.doc扩展名,如保存时用.cpp扩展名。

解决方案 »

  1.   

    CString szFilter ;
    szFilter =  "CPP文件(*.cpp)|*.cpp|所有文件 (*.*)|*.*||";
    CFileDialog dlg(FALSE, "CPP文件", "*.cpp", OFN_HIDEREADONLY , szFilter );
    dlg.m_ofn.lpstrInitialDir = ::G_Get2Dir(* sOPath);
    if (dlg.DoModal() == IDOK) 
    {
    * sOPath = dlg.GetPathName();//full file path
    }
      

  2.   

    CDocTemplate::GetDocString 
    virtual BOOL GetDocString( CString& rString, enum DocStringIndex index ) const;Return ValueNonzero if the specified substring was found; otherwise 0.ParametersrStringA reference to a CString object that will contain the string when the function returns.indexAn index of the substring being retrieved from the string that describes the document type. This parameter can have one of the following values: CDocTemplate::windowTitle   Name that appears in the application window’s title bar (for example, “Microsoft Excel”). Present only in the document template for SDI applications.
    CDocTemplate::docName   Root for the default document name (for example, “Sheet”). This root, plus a number, is used for the default name of a new document of this type whenever the user chooses the New command from the File menu (for example, “Sheet1” or “Sheet2”). If not specified, “Untitled” is used as the default.
    CDocTemplate::fileNewName   Name of this document type. If the application supports more than one type of document, this string is displayed in the File New dialog box (for example, “Worksheet”). If not specified, the document type is inaccessible using the File New command.
    CDocTemplate::filterName   Description of the document type and a wildcard filter matching documents of this type. This string is displayed in the List Files Of Type drop-down list in the File Open dialog box (for example, “Worksheets (*.xls)”). If not specified, the document type is inaccessible using the File Open command. 
    CDocTemplate::filterExt   Extension for documents of this type (for example, “.xls”). If not specified, the document type is inaccessible using the File Open command. 
    CDocTemplate::regFileTypeId   Identifier for the document type to be stored in the registration database maintained by Windows. This string is for internal use only (for example, “ExcelWorksheet”). If not specified, the document type cannot be registered with the Windows File Manager.
    CDocTemplate::regFileTypeName   Name of the document type to be stored in the registration database. This string may be displayed in dialog boxes of applications that access the registration database (for example, “Microsoft Excel Worksheet”). 
    Res
      

  3.   

    或者重载那两个函数自己写!
    参考:
    void CMyPlayerDlg::OnButtonOpen() 
    {
    // TODO: Add your control notification handler code here
    CString strFilter = "Mp3 File(*.mp3)|*.mp3|";
    strFilter += "MPEG File(*.mpg;*.mpeg)|*.mpg;*.mpeg|";
    strFilter += "Wave File(*.wav)|*.wav|";
    strFilter += "AVI File(*.avi)|*.avi|";
    strFilter += "All File(*.*)|*.*|";
    CFileDialog dlgOpen(TRUE,NULL,NULL,OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,strFilter,this);
    DWORD MAXFILE = 2412; // allocate enough memory space
    dlgOpen.m_ofn.nMaxFile = MAXFILE; // set the buffer size
    CString strFileName;
    char* buf = new char[MAXFILE];
    dlgOpen.m_ofn.lpstrFile = buf;
    dlgOpen.m_ofn.lpstrFile[0] = NULL; 
    if(IDOK == dlgOpen.DoModal())
    {
    POSITION pos = dlgOpen.GetStartPosition();
    while (pos != NULL)
    {
    strFileName = dlgOpen.GetNextPathName(pos); 
    // get the individual file name
    m_SourceFileList.InsertString(m_SourceFileList.GetCount(),strFileName);// add to Mp3 ListBox
    }
    }
    delete [] buf;
    }
      

  4.   

    IDR_MAINFRAME 
    YourApp\n\n\ncpp(*.mdb);\n.cpp\nYour.Document\nYour
      

  5.   

    IDR_MAINFRAME 
    YourApp\n\n\ncpp(*.cpp);\n.cpp\nYour.Document\nYour
      

  6.   

    //open
    CString strSel = _T("csvFiles(*.csv)|*.csv||");
    CFileDialog dlg(TRUE,_T("*.csv"),_T("*.csv"),
    OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,strSel);//save
    wchar_t szFilters[]= _T("File Out Files (*.csv)|*.csv||");
    CFileDialog fileDlg (FALSE, _T("*.csv"),_T("*.csv"),
     OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT, szFilters, this);