1
votes

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.

3
I don't understand "view inheriting from CWnd with a new view that inherits from CFormView".user34660

3 Answers

4
votes

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

2
votes

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.

1
votes

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.