简体   繁体   English

C ++ MFC MDI如何更改基于活动文档显示的类视图

[英]C++ MFC MDI how to change what class view displays based on active document

I'm working on an MDI application that has an object browser (CClassView) that has to change what it displays based on what "document" is active. 我正在使用具有对象浏览器(CClassView)的MDI应用程序,该对象浏览器必须根据活动的“文档”来更改其显示的内容。

PS: None of my searches have worked. PS:我的搜索都没有成功。

This isn't what I expected, but here's a possible solution: 这不是我期望的,但是这是一个可能的解决方案:

http://forums.codeguru.com/showthread.php?473808-MFC-Doc-View-How-to-get-the-active-document-anywhere-in-my-application http://forums.codeguru.com/showthread.php?473808-MFC-Doc-View-How-to-get-the-active-document-anywhere-in-my-application

Q: How to get the active document anywhere in my application? 问:如何在应用程序中的任何位置获取活动文档?

A: There are several methods, one is to get first the active frame then call CFrameWnd::GetActiveDocument. 答:有几种方法,一种是首先获取活动框架,然后调用CFrameWnd :: GetActiveDocument。 ... In MDI applications, we have to additionally get the active MDI child frame. 在MDI应用程序中,我们必须另外获得活动的MDI子框架。

CDocument* GetMDIActiveDocument()
{
    CDocument* pDoc = NULL;

    CWnd* pWndMain = AfxGetMainWnd();
    ASSERT(pWndMain);
    ASSERT(pWndMain->IsKindOf(RUNTIME_CLASS(CMDIFrameWnd))); // Not an MDI app.

    CFrameWnd* pFrame = ((CMDIFrameWnd*)pWndMain)->MDIGetActive();
    if(NULL != pFrame)
    {
        pDoc = pFrame->GetActiveDocument(); // get the active document
    }
    return pDoc;
}

This sample code might suggest other (perhaps even better) alternatives: 此示例代码可能会建议其他(也许更好)的替代方法:

http://msdn.microsoft.com/en-us/library/cstcs513%28v=vs.90%29.aspx http://msdn.microsoft.com/zh-CN/library/cstcs513%28v=vs.90%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM