WEB开发网
开发学院软件开发VC 深入浅出MFC“文档/视图”架构(2)――文档模板 阅读

深入浅出MFC“文档/视图”架构(2)――文档模板

 2009-02-11 20:00:37 来源:WEB开发网   
核心提示: CDocTemplate还提供了框架窗口的创建和初始化函数:/// Default frame creationCFrameWnd* CDocTemplate::CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther){ if (pDoc !=

CDocTemplate还提供了框架窗口的创建和初始化函数:

/////////////////////////////////////////////////////////////////////////////
// Default frame creation
CFrameWnd* CDocTemplate::CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther)
{
    if (pDoc != NULL)
       ASSERT_VALID(pDoc);
    // create a frame wired to the specified document
  
    ASSERT(m_nIDResource != 0); // must have a resource ID to load from
    CCreateContext context;
    context.m_pCurrentFrame = pOther;
    context.m_pCurrentDoc = pDoc;
    context.m_pNewViewClass = m_pViewClass;
    context.m_pNewDocTemplate = this;
  
    if (m_pFrameClass == NULL)
    {
       TRACE0("Error: you must override CDocTemplate::CreateNewFrame.n");
       ASSERT(FALSE);
       return NULL;
    }
    CFrameWnd* pFrame = (CFrameWnd*)m_pFrameClass->CreateObject();
    if (pFrame == NULL)
    {
       TRACE1("Warning: Dynamic create of frame %hs failed.n",
           m_pFrameClass->m_lpszClassName);
       return NULL;
    }
    ASSERT_KINDOF(CFrameWnd, pFrame);
  
    if (context.m_pNewViewClass == NULL)
       TRACE0("Warning: creating frame with no default view.n");
  
    // create new from resource
    if (!pFrame->LoadFrame(m_nIDResource,
           WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,  // default frame styles
           NULL, &context))
    {
       TRACE0("Warning: CDocTemplate couldn't create a frame.n");
       // frame will be deleted in PostNcDestroy cleanup
       return NULL;
    }
  
    // it worked !
    return pFrame;
}
void CDocTemplate::InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc,
    BOOL bMakeVisible)
{
    // just delagate to implementation in CFrameWnd
    pFrame->InitialUpdateFrame(pDoc, bMakeVisible);
}

上一页  5 6 7 8 9 10 

Tags:深入浅出 MFC 文档

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接