When I step into CMainFrame::OnAlohaHowAreYou(), I found m_pDoc is NULL. If I remove the split views and make CMainFrame::OnCreateClient() like below, then there is no problem.
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Originally Posted by sunnysky
When I step into CMainFrame::OnAlohaHowAreYou(), I found m_pDoc is NULL. If I remove the split views and make CMainFrame::OnCreateClient() like below, then there is no problem.
Your frame is not aware of active view. You have to explicitly access some of your views to get its corresponding document. Or set active view information otherwise.
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Originally Posted by sunnysky
I created two split views like this:
...
When I step into CMainFrame::OnAlohaHowAreYou(), I found m_pDoc is NULL. If I remove the split views and make CMainFrame::OnCreateClient() like below, then there is no problem.
...
What could be wrong?
You seem to have created your splitter from scratch without careful reading the docs and playing with samples like viewex.
Thus you missed to activate a view as Igor already mentioned.
However if you had looked at the viewex code you would see this important line:
Code:
BOOL CSplitterFrame::OnCreateClient(LPCREATESTRUCT,
CCreateContext* pContext)
{
// create a splitter with 1 row, 2 columns
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
TRACE0("Failed to CreateStaticSplitter\n");
return FALSE;
}
// add the first splitter pane - the default view in column 0
if (!m_wndSplitter.CreateView(0, 0,
pContext->m_pNewViewClass, CSize(130, 50), pContext))
{
TRACE0("Failed to create first pane\n");
return FALSE;
}
// add the second splitter pane - an input view in column 1
if (!m_wndSplitter.CreateView(0, 1,
RUNTIME_CLASS(CInputView), CSize(0, 0), pContext))
{
TRACE0("Failed to create second pane\n");
return FALSE;
}
// activate the input view
SetActiveView((CView*)m_wndSplitter.GetPane(0,1));
return TRUE;
}
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Thanks Victor. But I think it is not enough. I added "SetActiveView((CView*)m_wndSplitter.GetPane(0, 0));" before "return TRUE;" and it still doesn't work.
I stepped into CFrameWnd::GetActiveDocument() and found "CView* pView = GetActiveView();" still set pView to be NULL. There must be something else missed.
Also I think I need to set the member m_pDocument of my CFirstView and CSecondView objects to be the created CDocument object, but I haven't found how to do that either.
I will study the viewex sample to try to get more hints. I really don't find MSDN documents very helpful.
Originally Posted by VictorN
You seem to have created your splitter from scratch without careful reading the docs and playing with samples like viewex.
Thus you missed to activate a view as Igor already mentioned.
However if you had looked at the viewex code you would see this important line:
Code:
BOOL CSplitterFrame::OnCreateClient(LPCREATESTRUCT,
CCreateContext* pContext)
{
// create a splitter with 1 row, 2 columns
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
TRACE0("Failed to CreateStaticSplitter\n");
return FALSE;
}
// add the first splitter pane - the default view in column 0
if (!m_wndSplitter.CreateView(0, 0,
pContext->m_pNewViewClass, CSize(130, 50), pContext))
{
TRACE0("Failed to create first pane\n");
return FALSE;
}
// add the second splitter pane - an input view in column 1
if (!m_wndSplitter.CreateView(0, 1,
RUNTIME_CLASS(CInputView), CSize(0, 0), pContext))
{
TRACE0("Failed to create second pane\n");
return FALSE;
}
// activate the input view
SetActiveView((CView*)m_wndSplitter.GetPane(0,1));
return TRUE;
}
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Originally Posted by sunnysky
Thanks Victor. But I think it is not enough. I added "SetActiveView((CView*)m_wndSplitter.GetPane(0, 0));" before "return TRUE;" and it still doesn't work.
I stepped into CFrameWnd::GetActiveDocument() and found "CView* pView = GetActiveView();" still set pView to be NULL. There must be something else missed.
Could you post a very small test project (in zip archive noty including Debug/Release folders nor .aps, .res, .opt, .ncb files) reproducing the problem?
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Thanks Victor.
I created these view classes with the help of wizard and didn't add any code. My problem is that other than application specific members, I don't know which methods should be implemented by me and which ones are already provided by the framework.
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
For instance, the examples I saw don't call "CFrameWnd::OnCreateClient(lpcs, pContext)" in "CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext* pContext )", but I found that if I don't do that, I will have problems.
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
You could start with creating using the AppWizard a new SDI project with "Windows Explorer" style. Then remove unndeeded code, add/change what you need and use it!
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
Originally Posted by sunnysky
the examples I saw don't call "CFrameWnd::OnCreateClient(lpcs, pContext)" in "CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext* pContext )", but I found that if I don't do that, I will have problems.
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
But that will sacrifice flexibility. The Wizard only provide CListView and CTreeView.
Originally Posted by VictorN
You could start with creating using the AppWizard a new SDI project with "Windows Explorer" style. Then remove unndeeded code, add/change what you need and use it!
Re: Adding Splitter Windows Makes Mainframe Unable to Get Current Document
But you will see all the needed methods/calls/initializations!
Then compare with your own code... Perhaps you will want to add something tha your code does not have...
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.