争怎路由网/网站教程/内容

让对话框也支持多文档的使用

网站教程2024-07-12 阅读
BOOL CApp::InitInstance()
{
///////////////////////////////////
    m_pDocTemplate = new CMultiDocTemplate(
        IDR_MSG,    //user define
        RUNTIME_CLASS(MessageDoc),
        RUNTIME_CLASS(MessageFrame),      // main SDI frame window
        RUNTIME_CLASS(MessageView));
    AddDocTemplate(m_pDocTemplate);

    // Enable DDE Execute open
    EnableShellOpen();
    RegisterShellFileTypes(TRUE);

    // Parse command line for standard shell commands, DDE, file open
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);
//.....................
    ............
}
//..........
public:
    CMultiDocTemplate * m_pDocTemplate;
//...........

//响应函数 比如按钮
void CApp::OnManageMessage()
{
    ASSERT(m_pDocTemplate != NULL);

    CDocument* pDoc = NULL;
    CFrameWnd* pFrame = NULL;
    pDoc = m_pDocTemplate->CreateNewDocument();
    if (pDoc != NULL)
    {
        pFrame = m_pDocTemplate->CreateNewFrame(pDoc, NULL);
        if (pFrame != NULL)
        {
            m_pDocTemplate->SetDefaultTitle(pDoc);
            if (!pDoc->OnNewDocument())
            {
                pFrame->DestroyWindow();
                pFrame = NULL;
            }
            else
                m_pDocTemplate->InitialUpdateFrame(pFrame, pDoc, TRUE);
        }
        else
            delete pDoc;
    }
    if (pFrame == NULL ¦¦ pDoc == NULL)
        AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
    else
              .............


……

相关阅读