Microsoft Foundation Classes
MFC is a C++ class library that wraps Win32 API, providing object-oriented abstractions for Windows programming. It enables rapid development of professional desktop applications with features like document/view architecture, toolbars, and property sheets.
Why MFC in 2025?
- Mature Framework: Battle-tested over 30 years
- Rich UI Components: Ribbon, property grids, docking
- Document/View: Clean separation of data and presentation
- Enterprise Ready: Thousands of production applications
Creating an MFC Application
Visual Studio provides MFC Application Wizard for quick project setup.
// MyApp.h - Application class
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
// MyApp.cpp
BOOL CMyApp::InitInstance()
{
CWinApp::InitInstance();
// Create main frame
CMainFrame* pFrame = new CMainFrame;
if (!pFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
Document/View Architecture
// Document class - holds your data
class CMyDocument : public CDocument
{
protected:
CString m_strContent;
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
void SetContent(const CString& str) { m_strContent = str; }
CString GetContent() const { return m_strContent; }
};
// View class - displays the data
class CMyView : public CView
{
protected:
virtual void OnDraw(CDC* pDC);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
};
void CMyView::OnDraw(CDC* pDC)
{
CMyDocument* pDoc = GetDocument();
pDC->TextOut(10, 10, pDoc->GetContent());
}
Modern MFC Features
Office-Style Ribbon
// Create ribbon bar
CMFCRibbonBar m_wndRibbonBar;
m_wndRibbonBar.Create(this);
// Add category
CMFCRibbonCategory* pCategory =
m_wndRibbonBar.AddCategory(_T("Home"), IDB_HOME_LARGE, IDB_HOME_SMALL);
// Add panel
CMFCRibbonPanel* pPanel = pCategory->AddPanel(_T("Actions"));
// Add buttons
pPanel->Add(new CMFCRibbonButton(ID_FILE_NEW, _T("New"), 0, 0));
pPanel->Add(new CMFCRibbonButton(ID_FILE_OPEN, _T("Open"), 1, 1));
Docking Panes
// Create dockable pane
CDockablePane m_wndProperties;
m_wndProperties.Create(_T("Properties"), this, CRect(0, 0, 200, 400),
TRUE, ID_VIEW_PROPERTIES,
WS_CHILD | WS_VISIBLE | CBRS_LEFT);
m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndProperties);
UltraFluidModeler
Check out UltraFluidModelerNET - a real-world example of what's possible with MFC: a professional modeling tool with ribbon UI, property grid, tabbed documents, and infinite zoom/pan.
← Back to Developer Resources