在视图被创建的时候,在oncreate函数里视图和文档发生了关联:
int cview::oncreate(lpcreatestruct lpcs)
{
if (cwnd::oncreate(lpcs) == -1)
return -1;
ccreatecontext* pcontext = (ccreatecontext*)lpcs->lpcreateparams;
if (pcontext != null && pcontext->m_pcurrentdoc != null)
{
pcontext->m_pcurrentdoc->addview(this);
assert(m_pdocument != null);
}
else
{
trace0("warning: creating a pane with no cdocument.\n");
}
return 0;
}
这个关联是通过文档类的addview函数实现的:
void cdocument::addview(cview* pview)
{
……
m_viewlist.addtail(pview);
pview->m_pdocument = this;
onchangedviewlist();
}