-
April 10th, 2014, 02:37 PM
#31
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.
Originally Posted by VictorN
No, if you created the project with AppWizard to add splitter views.
-
April 10th, 2014, 03:04 PM
#32
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.
-
April 10th, 2014, 03:50 PM
#33
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Originally Posted by sunnysky
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
-
April 10th, 2014, 07:14 PM
#34
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Originally Posted by VictorN
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?
-
April 11th, 2014, 03:05 AM
#35
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
-
April 11th, 2014, 01:11 PM
#36
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?
Originally Posted by VictorN
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.
-
April 11th, 2014, 02:44 PM
#37
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Originally Posted by sunnysky
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!
Originally Posted by sunnysky
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
-
April 11th, 2014, 03:25 PM
#38
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?
Originally Posted by VictorN
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.
-
April 11th, 2014, 04:09 PM
#39
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
-
April 16th, 2014, 11:05 AM
#40
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.
-
April 16th, 2014, 11:11 AM
#41
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
-
April 16th, 2014, 12:45 PM
#42
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
-
April 16th, 2014, 02:35 PM
#43
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().
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|