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

发表于:2007-07-14来源:作者:点击数: 标签:
BOOL CApp::InitInstance() { /////////////////////////////////// m_pDocTemplate = new CMultiDocTemplate( IDR_MSG,//user define RUNTIME_CLASS(MessageDoc), RUNTIME_CLASS(MessageFrame),// main SDI frame window RUNTIME_CLASS(MessageView)); AddD
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
              .............

原文转自:http://www.ltesting.net