本文介绍了MFC SDI CDocument我如何进入视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在编写一种Explorer风格的MFC SDI应用程序,因此左侧具有树视图,称为CLeftView.我正在尝试将文件打开到另一个视图(称为CMyAppView).我可以按如下所示进行操作,但是请确保必须有更好的方法,因为我必须两次调用GetNextView,并且第一次尝试获取树状视图,而我不需要这样做.

Hi,
I am writing an MFC SDI Application which is explorer style, so has a tree-view on the left and is called CLeftView. I am trying to open a file into the other view (called CMyAppView). I can do it as shown below but am sure there must be a better way as I have to call GetNextView twice, and the first time it is attempting to get the tree-view, which i don''t need to do.

BOOL CMyAppDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
    ...........................
    POSITION posView = GetFirstViewPosition();
    //NOW NEED TO UPDATE VIEW
    // this is getting the CLeftView - I don't want this one
    ((CRichEditView*)GetNextView( posView ));//->SetWindowText(lpszDisplay); 

    // this is getting the CMyAppView
    ((CRichEditView*)GetNextView( posView ))->SetWindowText(lpszDisplay);
}



我应该如何从我的CDocument类访问主视图?

非常感谢!



How should I access the main view from my CDocument class?

many thanks!

推荐答案

CMDIFrameWnd *pFrame =
             (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;

// Get the active MDI child window.
CMDIChildWnd *pChild =
             (CMDIChildWnd *) pFrame->GetActiveFrame();

// or CMDIChildWnd *pChild = pFrame->MDIGetActive();

// Get the active view attached to the active MDI child
// window.
CMyView *pView = (CMyView *) pChild->GetActiveView();



这篇关于MFC SDI CDocument我如何进入视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 00:33