To reproduce the assertion:
Just create a new project and inherit the view class with CSrcollView. Extend your classes with
CMDIFrameWndEx, CMDIChildWndEx, CWinAppEx
repectively. Set scroll size in oninitialupdate of view class. Now run the progam without opening any window on startup. Open the document. New tab is created. Its working fine. Now add following lines in
CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
Code:
cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | FWS_ADDTOTITLE | WS_EX_CLIENTEDGE | WS_MAXIMIZEBOX | WS_MAXIMIZE;
Now u will get assertion at:
Code:
void CScrollView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
...
#ifdef
_DEBUG
if (m_nMapMode == MM_NONE){
TRACE(traceAppMsg, 0,
"Error: must call SetScrollSizes() or SetScaleToFitSize()");
TRACE(traceAppMsg, 0)
"\tbefore painting scroll view.\n");
ASSERT(FALSE);
return;
}
If i remove WS_VISIBLE style, then there is no assertion. I don't know the reason.
To resolve this i just added
Code:
m_nMapMode = MM_TEXT;
in constructor of view class.
So it is working fine. But still i don't understand why OnDraw is called before OnInitialUpdate() in this case as this is totally shaking my logic.
Now my actual problem starts. I have to call a function of a class in OnInitialUpdate. In that function I have to point view class object. i am getting view class like
(MyViewClass*)((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive()->GetActiveView())
on further modularising above line i came to know that MDIGetActive is returning null.
now can anyone help me out.