g;
在应用程序的派生类的头部添加以下代码:
#include "BubDoc.h"
#include "BubFrame.h"
#include "BubView.h"
并使用Class Wizard 创建ID_FILE_NEW_BUB ,ID_FILE_OPEN_BUB和ID_FILE_NEW_TXT的消息响应函数。
响应函数的代码如下:
void CMultiDoctempApp::OnFileNewTxt()
{
POSITION curTemplatePos = GetFirstDocTemplatePosition();
while (curTemplatePos != NULL)
{
CDocTemplate * curTemplate = GetNextDocTemplate(curTemplatePos);
CString str;
curTemplate->GetDocString(str,CDocTemplate::docName);
if (str == _T("Txt"))
{
curTemplate->OpenDocumentFile(NULL);
return;
}
}
AfxMessageBox("NO TXTTEMPALTE!");
}
void CMultiDoctempApp::OnFileNewBub()
{
POSITION curTemplatePos = GetFirstDocTemplatePosition();
while (curTemplatePos != NULL)
{
CDocTemplate * curTemplate = GetNextDocTemplate(curTemplatePos);
CString str;
curTemplate->GetDocString(str,CDocTemplate::docName);
if (str == _T("Bub"))
{
curTemplate->OpenDocumentFile(NULL);
return;
}
}
AfxMessageBox("NO BUBTEMPALTE!");
}
void CMultiDoctempApp::OnFileOpenBub()
{
POSITION curTemplatePos = GetFirstDocTemplatePosition();
while (curTemplatePos != NULL)
{
CDocTemplate * curTemplate = GetNextDocTemplate(curTemplatePos);
CString str;
curTemplate->GetDocString(str,CDocTemplate::docName);
if (str == _T("Bub"))
{
CFileDialog dlg(true);
if (dlg.DoModal() == IDOK)
{
CString path = dlg.GetPathName();
curTemplate->OpenDocumentFile(path);
}
return;
}
}
AfxMessageBox("NO TXTTEMPALTE!");
}
以上的介绍就是VC++环境下多文档模板应用程序开发的一个小例子。希望能够帮助到大家。
该篇文章参考知网上的论文资料本人总结所得。
源码的下载地址:http://download.csdn.net/my