资源ID=
\nSdfa\nSdfa\nSdfa 文件 (*.bmp)(*.jpg)\n.bmp\nSdfa.Document\nSdfa Document
我想在保存时,过滤框中*.bmp 和 *.jpg分行,能不能在这里改?我用如下方法可以实现的:
CString strSaveName = GetTitle();
CString filt="Bmp File(*.BMP)|*.bmp|Jpg File(*.JPG)|*.jpg|Tif File(*.TIF)|*.tif|Ico File(*.ICO)|*.ico|Png File(*.PNG)|*.png|Tga File(*.TGA)|*.tga|Pcx File(*.PCX)|*.pcx|All files (*.*)|*.*||";
CFileDialog dlg(FALSE, "", strSaveName, NULL, filt);但我不想自己处理OnFileSave函数,但可以重载OnSaveDocument。
怎么用最简单的方法实现?

解决方案 »

  1.   

    和下面一样写不可以吗?
    \nSdfa\nSdfa\Bmp File(*.BMP)|*.bmp|Jpg File(*.JPG)|*.jpg|\n.bmp\nSdfa.Document\nSdfa Document
      

  2.   

    char namebuf[8192];
    memset(namebuf, 0, 8192);
    static char BASED_CODE szFilter[] = "所有文件(*.*)|*.*|BMP位图(*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|JEPG文件(*.jpg;*.jpeg;*.jpe;*.jif)|*.jpg;*.jpeg;*.jpe;*.jif|GIF计算机服务(*.gif)|*.gif|ICO图标(*.ico)|*.ico|TIFF Tag图像(*.tif;*.tiff)|*.tif;*.tiff|Windows图元文件(*.wmf)|*.wmf|PNG便携网络图形(*.png)|*.png|TGA Targa(*.tga)|*.tga||";
    CPreviewFileDlg dlg(TRUE,NULL,NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
    dlg.m_ofn.lpstrFile = namebuf;
    dlg.m_ofn.nMaxFile = 8192;
    dlg.m_ofn.lpstrTitle = "选择需要上传的文件(可多选)";
    if(dlg.DoModal() == IDOK)
    {
    ...
    }
      

  3.   

    我想让系统自动弹出保存对话框。就是不用DoModal函数。
      

  4.   

    After some deep to the MFC source code,
    I'm afraid you couldn't change it if your project is just a SDI,
    because the "File Save AS" dialog box is actually done by CDocManager::DoPromptFileName.
    You can see that it calls _AfxAppendFilterSuffix() adding each suffix to the ofn,it won't
    add two or more for a single document template!
    You could see that there is only once adding operation ,no loop!!BOOL CDocManager::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate)
    {
    CFileDialog dlgFile(bOpenFileDialog); CString title;
    VERIFY(title.LoadString(nIDSTitle)); dlgFile.m_ofn.Flags |= lFlags; CString strFilter;
    CString strDefault;
    if (pTemplate != NULL)
    {
    ASSERT_VALID(pTemplate);
    _AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate, &strDefault);
    }
    else
    {
    // do for all doc template
    POSITION pos = m_templateList.GetHeadPosition();
    BOOL bFirst = TRUE;
    while (pos != NULL)
    {
    CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
    _AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
    bFirst ? &strDefault : NULL);
    bFirst = FALSE;
    }
    } // append the "*.*" all files filter
    CString allFilter;
    VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
    strFilter += allFilter;
    strFilter += (TCHAR)'\0';   // next string please
    strFilter += _T("*.*");
    strFilter += (TCHAR)'\0';   // last string
    dlgFile.m_ofn.nMaxCustFilter++; dlgFile.m_ofn.lpstrFilter = strFilter;
    dlgFile.m_ofn.lpstrTitle = title;
    dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH); int nResult = dlgFile.DoModal();
    fileName.ReleaseBuffer();
    return nResult == IDOK;
    }  AFX_STATIC void AFXAPI _AfxAppendFilterSuffix(CString& filter, OPENFILENAME& ofn,
    CDocTemplate* pTemplate, CString* pstrDefaultExt)
    {
    ASSERT_VALID(pTemplate);
    ASSERT_KINDOF(CDocTemplate, pTemplate); CString strFilterExt, strFilterName;
    if (pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt) &&
     !strFilterExt.IsEmpty() &&
     pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) &&
     !strFilterName.IsEmpty())
    {
    // a file based document template - add to filter list
    ASSERT(strFilterExt[0] == '.');
    if (pstrDefaultExt != NULL)
    {
    // set the default extension
    *pstrDefaultExt = ((LPCTSTR)strFilterExt) + 1;  // skip the '.'
    ofn.lpstrDefExt = (LPTSTR)(LPCTSTR)(*pstrDefaultExt);
    ofn.nFilterIndex = ofn.nMaxCustFilter + 1;  // 1 based number
    } // add to filter
    filter += strFilterName;
    ASSERT(!filter.IsEmpty());  // must have a file type name
    filter += (TCHAR)'\0';  // next string please
    filter += (TCHAR)'*';
    filter += strFilterExt;
    filter += (TCHAR)'\0';  // next string please
    ofn.nMaxCustFilter++;
    }
    }
      

  5.   

    Maybe you could do this by Add more dummy Doc Template to your app,
    however,it is not prefered!
      

  6.   

    it's MDI application. i also saw these when debug. 
    why not give lpszFilter's value?
    CFileDialog::CFileDialog(BOOL bOpenFileDialog,
    LPCTSTR lpszDefExt, LPCTSTR lpszFileName, DWORD dwFlags,
    LPCTSTR lpszFilter, CWnd* pParentWnd) : CCommonDialog(pParentWnd)
    {
    memset(&m_ofn, 0, sizeof(m_ofn)); // initialize structure to 0/NULL
    m_szFileName[0] = '\0';
    m_szFileTitle[0] = '\0';
    m_pofnTemp = NULL; m_bOpenFileDialog = bOpenFileDialog;
    m_nIDHelp = bOpenFileDialog ? AFX_IDD_FILEOPEN : AFX_IDD_FILESAVE; m_ofn.lStructSize = sizeof(m_ofn);
    m_ofn.lpstrFile = m_szFileName;
    m_ofn.nMaxFile = _countof(m_szFileName);
    m_ofn.lpstrDefExt = lpszDefExt;
    m_ofn.lpstrFileTitle = (LPTSTR)m_szFileTitle;
    m_ofn.nMaxFileTitle = _countof(m_szFileTitle);
    m_ofn.Flags |= dwFlags | OFN_ENABLEHOOK | OFN_ENABLESIZING;
    if (!afxData.bWin4 && AfxHelpEnabled())
    m_ofn.Flags |= OFN_SHOWHELP;
    if (afxData.bWin4)
    {
    m_ofn.Flags |= OFN_EXPLORER;
    m_ofn.hInstance = AfxGetResourceHandle();
    }
    m_ofn.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc; // setup initial file name
    if (lpszFileName != NULL)
    lstrcpyn(m_szFileName, lpszFileName, _countof(m_szFileName)); // Translate filter into commdlg format (lots of \0)
    if (lpszFilter != NULL)
    {
    m_strFilter = lpszFilter;
    LPTSTR pch = m_strFilter.GetBuffer(0); // modify the buffer in place
    // MFC delimits with '|' not '\0'
    while ((pch = _tcschr(pch, '|')) != NULL)
    *pch++ = '\0';
    m_ofn.lpstrFilter = m_strFilter;
    // do not call ReleaseBuffer() since the string contains '\0' characters
    }
    }
    what's dummy doc template, how to do that?