在多文档界面中创建文档并修改标题名
创建文档模板代码。
1 | // create doc template |
创建Doc并加入DocManager
void CXXApp::OnFileNew()
{
if (NULL == m_pDocManager)
return;
// first template position
POSITION posTemplate = m_pDocManager->GetFirstDocTemplatePosition();
// if NULL no template
if (NULL == posTemplate)
{
return;
}
// first template
CDocTemplate* pTemplate = m_pDocManager->GetNextDocTemplate(posTemplate);
if (!pTemplate)
return;
// create new doc and add to manager
CDocument* pDoc = pTemplate->OpenDocumentFile(NULL);
if (!pDoc)
{
return;
}
// set doc title
pDoc->SetTitle(_T("127.0.0.1"));
// unnecessary
// Test is not the first document
POSITION posDoc = pTemplate->GetFirstDocPosition();
if (posDoc)
{
auto p = pTemplate->GetNextDoc(posDoc);
if (p == pDoc)
{
TRACE(_T("new doc title is %s\n"), p->GetTitle());
}
else
{
TRACE(_T("first doc title is %s\n"), p->GetTitle());
TRACE(_T("new doc title is %s\n"), pDoc->GetTitle());
}
}
// unnecessary
}
`
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 张拓的博客!