The Microsoft Foundation Class (MFC) Library provides an object-oriented C++ wrapper over much of the Win32 API and COM interfaces, enabling developers to build rich Windows desktop applications more rapidly than raw Win32 programming allows. MFC has been a cornerstone of Windows desktop development since 1992 and remains fully supported in modern Visual Studio — though it no longer receives new features. It is most suitable for maintaining existing MFC codebases or rapidly building complex UI-driven applications that leverage features such as toolbars, docking panes, ribbon bars, and Office-style interfaces.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/MicrosoftDocs/cpp-docs/llms.txt
Use this file to discover all available pages before exploring further.
The MFC library continues to be supported in Visual Studio, but new features and documentation updates have ceased. For new projects, consider WinUI 3, Qt, or raw Win32 with DirectX depending on your needs.
What MFC Provides
Window & Control Wrappers
Classes like
CWnd, CButton, CEdit, CListCtrl wrap every Win32 window and common control, providing C++ encapsulation with virtual function dispatch.Document-View Architecture
CDocument and CView separate data from presentation, enabling multiple simultaneous views on the same document with built-in serialization support.Message Maps
The
BEGIN_MESSAGE_MAP / END_MESSAGE_MAP macro system routes Windows messages (WM_PAINT, WM_LBUTTONDOWN, etc.) to C++ member functions without a manual switch statement.GDI Wrappers
CDC, CPen, CBrush, CFont, and CBitmap wrap GDI device contexts and drawing objects with RAII semantics.Dialog & Resource Support
CDialog, CFileDialog, CColorDialog wrap Windows common dialogs; CDataExchange (DDX/DDV) binds dialog controls to member variables automatically.Collections & Serialization
CArray, CList, CMap provide typed collections. CArchive and Serialize() enable binary object persistence with versioning support.The MFC Class Hierarchy
The entire MFC library descends fromCObject, which provides runtime class identification, serialization, and diagnostic support. Below is a simplified view of the most important inheritance chains:
Document-View Architecture
The document-view pattern is the organizing principle of MFC applications. Documents store data; views render it. Multiple views can display the same document simultaneously, and the framework synchronizes them automatically.CDocument — Data Model
Stores the application data. Implements
Serialize() for reading/writing to CArchive. Calls UpdateAllViews() to notify views when data changes.CView — Presentation Layer
Renders the document in the client area. Receives
OnDraw() calls from the framework. Calls GetDocument() to access data.CFrameWnd — Window Shell
Hosts the view, provides the menu bar, toolbar, and status bar. Handles frame-level messages and command routing.
Message Maps
MFC replaces the Win32WndProc with a declarative message map system. Each class declares which Windows messages it handles using macros:
When to Use MFC vs Alternatives
Use MFC when...
Use MFC when...
- You are maintaining or extending an existing MFC codebase
- You need Office-style UI quickly: ribbon bars, docking panes, property grids
- Your team already has MFC expertise and tight deadlines
- You require deep integration with legacy COM/OLE components
Consider raw Win32 when...
Consider raw Win32 when...
- You need maximum control over window creation, message handling, and painting
- Your application is a service, background process, or lightweight utility with minimal UI
- You want zero framework overhead and a minimal binary footprint
Consider WinUI 3 / XAML Islands when...
Consider WinUI 3 / XAML Islands when...
- You are building a new desktop application for Windows 10/11
- You want modern Fluent Design controls, touch support, and accessibility
- You need compositing and GPU-accelerated rendering without MFC overhead
Simple MFC Window Example
Here is a minimal MFC application that creates a frame window and displays text:To compile MFC applications, your project must set Use of MFC to Use MFC in a Shared DLL or Use MFC in a Static Library in Project Properties → General. The MFC header
<afxwin.h> replaces <windows.h>.