Tutorial :MFC without document/view architecture



Question:

I'd like some help on using MFC without the document/view architecture.

I created a project without doc/view support, Visual C++ created a CFrameWnd and a view that inherits from CWnd. I replaced the view inheriting from CWnd with a new view that inherits from CFormView.

However, when I run my program, after I close the window I get a heap corruption error.


Solution:1

If inside where the frame window handles WM_CREATE, you change the code to create the instance of CFormView with the "magic" id of AFX_IDW_PANE_FIRST, you'll find it becomes the view for the frame window. This is due to the behaviour of CFrameWnd::InitialUpdateFrame(), which will be called from within MFC. The MSDN page comments on this helpful little feature:

http://msdn.microsoft.com/en-us/library/ch3t7308.aspx


Solution:2

Since you want to use the dialog editor and you don't want the document/view architecture, then maybe a "Dialog based" application is what you need.


Solution:3

The problem is MFC's lifecycle management. The view declaration (created by Visual C++ wizard) is:

CChildView        m_wndView;  

I replaced the above code with:

CChildFormView    m_wndView;  

CChildView inherits from CWnd, CChildFormView inherits from CFormView. Both views were created by the wizard, but only CChildFormView uses the DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE macros.

Since m_wndView is being created in the stack, when MFC automagically calls delete I get the error.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »