December 20th, 2012, 01:53 AM
[RESOLVED] MDI Child Splitter crashes on closing last view
I previously posted on how to create an MFC MDI Child splitter.
Thread: Problem splitting child window in MFC MDI program and a small demo has been attached to that thread.
Greatly expanding on the concept, I have a similar application built on the same type of framework with syntax colorization and an 'isense-like' capability based on CMFCToolTip. All works well except when I go to close the last (obligatory) view tab to obtain the grey-window, the app crashes.
The simple demo attached to the above thread (the last one) upon which my problem app was built DOES NOT exhibit this problem. I cannot figure out what the problem is. There are a number of postings on MFC MDI split child crashes but none have offered a workable solution.
LRESULT CWnd::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
if (m_pfnSuper != NULL)
return ::CallWindowProc(m_pfnSuper, m_hWnd, nMsg, wParam, lParam);
if ((pfnWndProc = *GetSuperWndProcAddr()) == NULL)
return ::DefWindowProc(m_hWnd, nMsg, wParam, lParam);
==> return ::CallWindowProc(pfnWndProc, m_hWnd, nMsg, wParam, lParam);
Unfortunately I cannot post the actual app that is giving me the problem as it is far too large. But it follows the same basic plan as the demo, but utilizes a number of DLLs.
Any help greatly appreciated.
Edit 12.20.2012 - Further info.
On a Wn2K machine the call stack shows a different problem. I think I know where the problem arises, but it is far to lengthy a discussion to post here. It most likely has to do with a status bar cursor position updater that I have incorporated in the main view. An interesting question is why debugging on different machines results in very different call-stack outputs??
On the Win2K machine, the debugger call-stack showed the offending code to be on my custom status bar updater designed to indicate the line and column of the view cursor.
The offending code and it's correction to ameliorate the problem is as follows: Note that the problem is that the CRichEditCtrl pointer, m_wndEditCtrl, is NULL when there is no view page present (gray window), but the updater is still trying to update the line number, so appcrashes.
Once again, a non-obvious null pointer causes a serious problem.
void CMainFrame::OnUpdateCurPosIndicator(CCmdUI *pCmdUI)
int nLineNum, nColNum;
long nSelStart, nSelEnd;
nLineNum = nColNum = 0;
nSelStart = nSelEnd = 0;
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame();
CCinView * cv = (CCinView*)pChild->GetActiveView();
m_wndEditCtrl = &cv->GetRichEditCtrl();
>> if(m_wndEditCtrl == NULL) return; // avoid crash on final close
m_wndEditCtrl->GetSel(nSelStart, nSelEnd); TRACE1("nSelStart = %d\n", nSelStart);
nLineNum = m_wndEditCtrl->LineFromChar(nSelStart);
nColNum = nSelStart - m_wndEditCtrl->LineIndex(nLineNum);
strCurPos.Format(ID_INDICATOR_CURPOS, nLineNum+1, nColNum+1);
}// OnUpdateCurPosIndicator(CCmdUI *pCmdUI)
Last edited by Mike Pliam; December 20th, 2012 at 12:01 PM.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.