多文档视图MFC软件,在软件打开后同时打开不同视图方法

添加不同视图文档模板

XXX.h头文件添加变量:

CMultiDocTemplate   *m_pTimeWaveDoc;
CMultiDocTemplate   *m_pEngWaveDoc;
CMultiDocTemplate   *m_pMatchWaveDoc;

XXX.cpp源文件中的BOOL CXXXApp::InitInstance()函数中添加不同视图文档模板:

    m_pTimeWaveDoc = new CMultiDocTemplate(IDR_XXXTYPE,
        RUNTIME_CLASS(CXXXDoc),
        RUNTIME_CLASS(CChildFrame),
        RUNTIME_CLASS(CTimeWaveView));
    if (!m_pTimeWaveDoc)
        return FALSE;

    AddDocTemplate(m_pTimeWaveDoc);

   m_pEngWaveDoc = new CMultiDocTemplate(IDR_XXXTYPE,
       RUNTIME_CLASS(CXXXDoc),
       RUNTIME_CLASS(CChildFrame),
       RUNTIME_CLASS(CEngWaveView));
   if (!m_pEngWaveDoc)
       return FALSE;
   AddDocTemplate(m_pEngWaveDoc);

   m_pMatchWaveDoc = new CMultiDocTemplate(IDR_XXXTYPE,
       RUNTIME_CLASS(CXXXDoc),
       RUNTIME_CLASS(CChildFrame),
       RUNTIME_CLASS(CMatchWaveView));
   if (!m_pMatchWaveDoc)
       return FALSE;
   AddDocTemplate(m_pMatchWaveDoc);

重写Doc类的OnOpenDocument方法

XXXDoc.h头文件中增加函数声明:

virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);

XXXDoc.cpp源文件中增加函数实现:

BOOL CXXXDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
    //防止出现打开文档失败提示
    return TRUE;
}

CXXXApp类添加OnFileNew函数

XXX.h头文件添加函数声明

void OnFileNew()

XXX.cpp添加函数实现

void CXXXApp::OnFileNew()
{
    m_pTimeWaveDoc->OpenDocumentFile(_T("时域图"));
    m_pEngWaveDoc->OpenDocumentFile(_T("能量谱"));
    m_pMatchWaveDoc->OpenDocumentFile(_T("符合曲线"));
}

修改ID_FILE_NEW关联代码

XXX.cpp的消息映射中修改ID_FILE_NEW关联函数:

ON_COMMAND(ID_FILE_NEW, &CXXXApp::OnFileNew)

你可能感兴趣的:(VC,and,C++)