我的程序中希望能根据不同的文件类型打开不同的视图(不知这样说是否正确),意思就是如果是文本则用CEditView这类的视图打开,而图像则用另一套,现在我不太清楚如何动态改变这些视图。
    另外根据类型不同动态加载菜单,希望能得到详细解答,最好能帮给个程序例子,谢谢了。
程序请寄:[email protected]

解决方案 »

  1.   

    如何打开多个视图已经试出来了,只是我想根据“打开”对话框选择文件,根据文件类型决定用哪个视图模版,请问应如何响应OpenFile事件呢?
      

  2.   

    我重载CDocument* CIntegralEnviromentApp::OpenDocumentFile(LPCTSTR lpszFileName) 函数后,的确是打开了正确的模版,但是程序还同时打开了其他的模版的视图,这是为什么?是否因为我在下面的程序中又打开了一次文档的原因,是否应当只激活一个模版视图就行了,那么激活模版视图的方法是什么呢?回答完这个问题就给分,谢谢!:)
    CDocument* CIntegralEnviromentApp::OpenDocumentFile(LPCTSTR lpszFileName)
    {
    // TODO: Add your specialized code here and/or call the base class
    TRACE("\n\n\nlpszFileName=%s\n\n\n",lpszFileName);
    CDocument* TempDoc=CWinApp::OpenDocumentFile(lpszFileName);
    //--------setActiveTemplate------------------------------------------
    int m_nFileType=0;
    CString s_cFileType="";
    BOOL m_bIsFileOrImage=TRUE;
    if(lpszFileName!="")
    {
    s_cFileType=lpszFileName;
    s_cFileType=s_cFileType.Right(3);
    s_cFileType.MakeLower();
    m_nFileType=USR_NONE;
    if(s_cFileType=="bmp")
    {
    m_nFileType=USR_BMP;
    m_bIsFileOrImage=FALSE;
    }
    if(s_cFileType=="jpg")
    {
    m_nFileType=USR_JPG;
    m_bIsFileOrImage=FALSE;
    }
    if(s_cFileType=="gif")
    {
    m_nFileType=USR_GIF;
    m_bIsFileOrImage=FALSE;
    }
    if(s_cFileType=="txt")
    m_nFileType=USR_TXT;
    }
    POSITION curTemplatePos = GetFirstDocTemplatePosition();
    CDocTemplate* curTemplate;
    switch(m_bIsFileOrImage)
    {
    case FALSE:
    while(curTemplatePos != NULL)
    {
    curTemplate =GetNextDocTemplate(curTemplatePos);
    CString str;
    curTemplate->GetDocString(str, CDocTemplate::docName);
    if(str == _T("图形文档"))
    {
    curTemplate->OpenDocumentFile(lpszFileName);
    break;
    }
    }
    break;
    case TRUE:
    while(curTemplatePos != NULL)
    {
    curTemplate =GetNextDocTemplate(curTemplatePos);
    CString str;
    curTemplate->GetDocString(str, CDocTemplate::docName);
    if(str == _T("可编辑文档"))
    {
    curTemplate->OpenDocumentFile(lpszFileName);
    break;
    }
    }
    break;
    }
    //--------setActiveTemplate------------------------------------------
    return TempDoc;
    }
      

  3.   

    终于解决了,屏蔽掉CDocument* TempDoc=CWinApp::OpenDocumentFile(lpszFileName);
    把curTemplate->OpenDocumentFile(lpszFileName);改为return curTemplate->OpenDocumentFile(lpszFileName);
      

  4.   

    若建立一个基于CEditView的程序,用打开对话框选取文件后,程序可以自动打开文本并显示。而我的程序是继承了一个CEditView,如何在打开后显示内容。