ODBC3 - MFC

CRecordView

2025-12-24

Written by: xiaobin

Use the CFormView template, and then manually rewrite it as CRecordView.

CObject
    CCmdTarget
        CWnd
            CView
                CScrollView
                    CFormView
                        CRecordView

NOTE!!! The database wizard is no longer provided in VS2017 and later versions.

application wizard - step6 (Figure: Step 6 of the MFC Application Wizard in Visual Studio 2013)

database support

Implement database support in CRecordView.

impl

// CMFCApplication1View database support
CRecordset* CMFCApplication1View::OnGetRecordset()
{
	return m_pSet;
}

declare

// Overrides
public:
	virtual CRecordset* OnGetRecordset();

Document/View

A document is a collection of data in your application with which the user interacts.

Although the word document seems to imply something of a textual nature, it isn’t limited to text. It could be data for a game, a geometric model, a text file, or, indeed, anything you want.

The term document is just a convenient label for the application data in your program, treated as a unit.

member

// Attributes
public:
	CRec1Set m_Rec1Set;

you add your own data members to store items that your application requires.

init

Initialization is performed in “MFCApplication1View.cpp”.

	// TODO: add construction code here
	m_pSet = nullptr;

define

public:
#ifdef AFX_DESIGN_TIME
	enum{ IDD = IDD_MFCAPPLICATION1_FORM };
#endif
	CRec1Set* m_pSet;

at “MFCApplication1View.h”

Figure 12-2 uses dashed arrows to show how pointers are used to relate objects. These pointers enable function members of one object to access the public data or function members in the interface of another object.

OnInitialUpdate

	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	m_pSet = &GetDocument()->m_Rec1Set;
	CRecordView::OnInitialUpdate();

member functions(GetDocument()) to support processing of that data.

Ref