从上面看出模板类的opendocumentfile函数里,利用createnewdocument对象使文档对象与模板对象建立了联系,利用了createnewframe函数使框架窗口与文档、视图、模板发生了联系:
cframewnd* cdoctemplate::createnewframe(cdocument* pdoc, cframewnd* pother)
{
if (pdoc != null)
assert_valid(pdoc);
assert(m_nidresource != 0); // 必须有资源id
ccreatecontext context;
context.m_pcurrentframe = pother;
context.m_pcurrentdoc = pdoc;
context.m_pnewviewclass = m_pviewclass;
context.m_pnewdoctemplate = this;
if (m_pframeclass == null)
{
……
}
cframewnd* pframe = (cframewnd*)m_pframeclass->createobject();
if (pframe == null)
{
……
return null;
}
assert_kindof(cframewnd, pframe);