资源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。
怎么用最简单的方法实现?
\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。
怎么用最简单的方法实现?
解决方案 »
- 新人求教
- 客户端socket编程需要用线程吗
- 为什么基于PNG做的程序在某些电脑上不能显示呢?
- 看看那里错了?
- 自己写的MFC ActiveX怎样去掉License验证
- 单文档、多文档中的视图、文档、框架之间的联系在那里定义,如我不想用应用程序向导创建单文档或多文档应用程序,我想从空工程里建起程序
- 关于数据类型转化的问题,急!
- 怎样打开WORD文件??
- long x1; double x2=1.47126; x1=x2;]===>这样一个关系,我如何尽量减少误差!?
- 我想学程序员
- 在程序中怎么指定combobox(CBS_DROPDOWN)edit框里显示的字符串?
- 把缓冲区的内容写入磁盘,这段代码有何问题?
\nSdfa\nSdfa\Bmp File(*.BMP)|*.bmp|Jpg File(*.JPG)|*.jpg|\n.bmp\nSdfa.Document\nSdfa Document
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)
{
...
}
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++;
}
}
however,it is not prefered!
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?