做单文档程序时,默认打开文档后缀为(*.*)。如果我们需要自定义打开后缀时,需要对文档模板相关函数做重载。
- class CMySingleDocTemplate : public CSingleDocTemplate
- {
- public:
- CMySingleDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
- CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass):\
- CSingleDocTemplate( nIDResource, pDocClass, pFrameClass, pViewClass )
- {
- }
- virtual BOOL GetDocString(CString& rString, enum DocStringIndex index) const
- {
- if(index == CDocTemplate::filterExt)
- {
- rString = _T(".test");
- }
- else if( index == CDocTemplate::fileNewName || index == CDocTemplate::filterName )
- {
- rString = _T("test(*.test)");
- }
- else
- {
- __super::GetDocString(rString,index);
- }
- return TRUE;
- };
- };
创建代码修改,CSingleDocTemplate改为CMySingleDocTemplate。
- CMySingleDocTemplate* pDocTemplate;
- pDocTemplate = new CMySingleDocTemplate(
- IDR_MAINFRAME,
- RUNTIME_CLASS(CMCDemoDoc),
- RUNTIME_CLASS(CMainFrame), // main SDI frame window
- RUNTIME_CLASS(CMC3DView));
- if (!pDocTemplate)
- return FALSE;
则打开文件,默认类型为自定义的后缀。