Re: using Document object from CFrameWnd
nexolite wrote:
Now one more amazing thing to see!
I created a simple SDI app to test all this ,in that I create two splitters
if(!m_wndSplitter.CreateStatic(this,1,2)||
!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CMyFrame),CSize(0,0),pContext)||
!m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CMypView),CSize(0,0),pContext))
return FALSE;
In CMyFrame I am not able to get the document pointer as before and
in CMyView I am able to get it using GetDocument() BUT..
If try to use the same thing that I used in CMyFrame to get the pointer i.e:
CFrameWnd* pFrame=(CFrameWnd*)AfxGetMainWnd();
CSDIExpDoc* pDoc=(CSDIExpDoc*)pFrame->GetActiveDocument();
I am NOT able to get the pointer this way!
and also have anybody used a CFrameWnd in a splitter window(as a view) and
got the document pointer??
nexolite:
I think perhaps that when your frame window (the one in the splitter) is active,
there is no active view, and so your main frame window cannot return the active
document.
Actually, although I suggested it, this "reaching out" to get things like the
current document is not a good OOP practice. When you create the windows in the
splitter, the active SDI document should be in the m_pCurrentDoc member of the
CCreateContext object. Perhaps you should feed this pointer *into* your frame
window object, and store it in a member variable.
--
David Wilkinson
Visual C++ MVP