CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 43 of 43
  1. #31
    sunnysky Guest

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    I used "MFC Standard" to create a brand new project. I didn't add any splitter views. Then I override OnCreateClient() in CMainFrame like this.

    Code:
    BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext* pContext )
    {
    	return TRUE;
    }
    In this case CFrameWnd::OnCreateClient() is not called.

    Quote Originally Posted by VictorN View Post
    No, if you created the project with AppWizard to add splitter views.

  2. #32
    sunnysky Guest

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    Then I created a "Windows Explorer" style application. The wizard created OnCreateClient() in CMainFrame. But CFrameWnd::OnCreateClient() is not called this time. However, CFrameWnd::InitialUpdateFrame() successfully get a valid pWnd.

    Don't understand why this works.

  3. #33
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    Quote Originally Posted by sunnysky View Post
    I used "MFC Standard" to create a brand new project. I didn't add any splitter views. Then I override OnCreateClient() in CMainFrame like this.

    Code:
    BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext* pContext )
    {
    	return TRUE;
    }
    In this case CFrameWnd::OnCreateClient() is not called.
    Sure it cannot be called! Just because you have overridden it!
    Now tell us why did you do it? Didn't you read MSDN? You have to!
    Remarks
    Never call this function.
    The default implementation of this function creates a CView object from the information provided in pContext, if possible.
    Override this function to override values passed in the CCreateContext object or to change the way controls in the main client area of the frame window are created. The CCreateContext members you can override are described in the CCreateContext class.
    Since you do not call it and do NOT provide any other view creation no view is created at all!
    Victor Nijegorodov

  4. #34
    sunnysky Guest

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    Quote Originally Posted by VictorN View Post
    Sure it cannot be called! Just because you have overridden it!
    Now tell us why did you do it? Didn't you read MSDN? You have to!Since you do not call it and do NOT provide any other view creation no view is created at all!
    So I was right in post 27, wasn't I?

  5. #35
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    No, you was not!
    Since you provide your own view creation procedure (with a splitter window containing some panes) you do NOT need to call the base class OnCreateClient().
    If you do not provide you own view creation procedure then you either have touse the the default procedure that is implemented in the CFrameWnd::OnCreateClient() or you won"t have any view window at all.
    Note that if you do not provide you own view creation procedure you do not neet to override the OnCreateClient() either. In that case the default implementation will be called by the framework automatically.
    Victor Nijegorodov

  6. #36
    sunnysky Guest

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    When a "Windows Explorer" application is created, the SetActiveView() function is successfully called in CFrameWnd::InitialUpdateFrame(). While I create splitter windows, SetActiveView() in CFrameWnd::InitialUpdateFrame() is not called.

    CFrameWnd::OnCreateClient() was not called in the application created by the wizard either. So why does pWnd = GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE) returns a non-NULL pointer?

    Quote Originally Posted by VictorN View Post
    No, you was not!
    Since you provide your own view creation procedure (with a splitter window containing some panes) you do NOT need to call the base class OnCreateClient().
    If you do not provide you own view creation procedure then you either have touse the the default procedure that is implemented in the CFrameWnd::OnCreateClient() or you won"t have any view window at all.
    Note that if you do not provide you own view creation procedure you do not neet to override the OnCreateClient() either. In that case the default implementation will be called by the framework automatically.

  7. #37
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    Quote Originally Posted by sunnysky View Post
    When a "Windows Explorer" application is created, the SetActiveView() function is successfully called in CFrameWnd::InitialUpdateFrame(). While I create splitter windows, SetActiveView() in CFrameWnd::InitialUpdateFrame() is not called.
    Debug your code to find out why it is not called!

    Quote Originally Posted by sunnysky View Post
    CFrameWnd::OnCreateClient() was not called in the application created by the wizard either. So why does pWnd = GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE) returns a non-NULL pointer?
    It returns a non-NULL pointer just because the view with AFX_IDW_PANE_FIRST does exist!
    Victor Nijegorodov

  8. #38
    sunnysky Guest

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    That's what I want to find out. Why does it exist this time?
    Quote Originally Posted by VictorN View Post
    It returns a non-NULL pointer just because the view with AFX_IDW_PANE_FIRST does exist!
    Besides, how does m_pDocument get set in the two views that the wizard creates? I debugged in to the CSingleDocTemplate constructor but could find how the wizard link the document to the views.

  9. #39
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    Again! Debug and read the docs! And sorry, I cannot help you now because I am posting from the laptop that has no VS at all.
    Victor Nijegorodov

  10. #40
    sunnysky Guest

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    I finally figured out what the problem is.

    The problem is the CTabView as Victor pointed out in post #9.

    My CSecondView class inherits CTabView. So I need to override OnInitialUpdate() like:

    Code:
    void CSecondView::OnInitialUpdate()
    {
    	CTabView::OnInitialUpdate();
    	AddView(RUNTIME_CLASS(CTestView), _T("Test"));
    }
    My CMainFrame::OnCreateClient() function just need to be like:

    Code:
    BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext* pContext )
    {
    	//CFrameWnd::OnCreateClient(lpcs, pContext);
    
    	if (!m_wndSplitter.CreateStatic (this, 1, 2) ||
    		!m_wndSplitter.CreateView (0, 0, RUNTIME_CLASS (CFirstView),
                CSize (256, 0), pContext) ||
            !m_wndSplitter.CreateView (0, 1, RUNTIME_CLASS (CSecondView),
                CSize (0, 0), pContext))
            return FALSE;
    
    	//SetActiveView((CView*)m_wndSplitter.GetPane(0, 0));
    
    	return TRUE;
    }
    I don't need to call CFrameWnd::OnCreateClient() as Victor pointed out in several posts because CSplitterWnd::CreateView() will pWnd->Create(), just like CFrameWnd::CreateView() calls pView->Create().

    I don't need to call SetActiveView() either because CFrameWnd::InitialUpdateFrame() will call SetActiveView() because AFX_IDW_PANE_FIRST does exist.

  11. #41
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    I am glad you have not only solved your initial problem but also understood a lot of how MFC framework works!
    Victor Nijegorodov

  12. #42
    sunnysky Guest

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    I feel very grateful.

  13. #43
    sunnysky Guest

    Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document

    I also figured out how m_pDocument in each view is set.

    When creating views in CMainFrame::OnCreateClient(), CView::OnCreate() is called for each view to be created. In CView::OnCreate(), the statement pContext->m_pCurrentDoc->AddView(this) will add a view and set its m_pDocument to be pContext->m_pCurrentDoc. pContext is set earlier indirectly by CWinApp::OnFileNew() and CWinApp::OnFileNew() was called by ProcessShellCommand(cmdInfo) in CTestApp::InitInstance().

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured