What Is MFC?
MFC (Microsoft Foundation Classes) is a C++ class library, shipped with Visual Studio since 1992, that wraps the raw Windows API (Win32) in a hierarchy of classes such as CWnd, CDialog, CDocument and CView. Instead of manually registering a window class and writing a WndProc switch statement to handle messages, an MFC developer derives from a base class and overrides virtual functions, letting the framework manage the underlying handles, message loop, and resource cleanup.
Cricket analogy: Just as a franchise like Mumbai Indians relies on a coaching structure rather than each player improvising net practice alone, MFC gives every window a base class (CWnd) so developers don't reinvent message-handling drills for each new form.
History and Purpose
MFC shipped with Visual C++ 1.0 in 1992, at a time when writing a Windows application in C meant manually calling RegisterClass, CreateWindow, and running a GetMessage/DispatchMessage loop, with every window procedure written as a giant switch statement over WM_ messages. MFC's founding purpose was to encapsulate these Win32 primitives inside reusable C++ classes so that common patterns - a main frame window, a menu, a modal dialog, a toolbar - could be built by deriving from a base class and overriding a handful of virtual functions rather than re-implementing boilerplate plumbing on every project.
Cricket analogy: The 1992 arrival of MFC parallels the introduction of the DRS review system in cricket: it didn't change the sport's fundamentals but wrapped umpiring decisions in a more structured, repeatable process, just as MFC wrapped WM_ message handling in structured virtual functions.
Core Components
The framework is organized around a small set of foundational classes. CObject sits at the root of most of the hierarchy and provides runtime type information (via the DECLARE_DYNAMIC/DECLARE_SERIAL macros) and built-in serialization support. CWnd wraps a Win32 HWND and exposes window operations - moving, resizing, painting, capturing input - as ordinary C++ member functions instead of API calls that take a handle parameter. CWinApp represents the single running instance of the application and owns the main message pump, while CDocument and CView implement the Document/View split that separates an application's underlying data from how that data is drawn and edited on screen, a pattern covered in detail later in this course.
Cricket analogy: CObject sitting at the root of the MFC hierarchy is like the ICC's playing conditions document underpinning every format of the game - Test, ODI, T20 all inherit the same base rules (LBW, run-out) the way every MFC class inherits serialization from CObject.
// Minimal MFC application skeleton
#include <afxwin.h>
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMyFrame : public CFrameWnd
{
public:
CMyFrame()
{
Create(NULL, _T("My First MFC Window"));
}
};
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMyFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CMyApp theApp; // the single global application objectThe single global 'theApp' instance in the skeleton above is what the AppWizard (or Project Wizard in modern Visual Studio) generates automatically for you - instantiating a CWinApp-derived object is what starts the whole MFC runtime, including its message pump, before your InitInstance override even runs.
When to Use MFC Today
MFC remains a defensible choice specifically for maintaining or extending existing native Windows desktop codebases - engineering CAD tools, laboratory instrumentation software, or internal line-of-business utilities that were originally written in it decades ago - because rewriting a mature, working application in a newer framework like WPF or WinUI 3 carries real schedule and regression risk. For a brand-new greenfield project, however, most teams today evaluate WPF, WinUI 3, or a cross-platform toolkit like Qt first, reserving MFC for the specific case where you are already inside an MFC codebase or need thin, low-overhead COM/ActiveX control hosting.
Cricket analogy: Sticking with MFC for a legacy codebase is like a Test team continuing to field a proven veteran opener with a 15-year technique rather than benching him for an unproven rookie mid-series - you keep what already works reliably under match pressure.
MFC is in maintenance mode: Microsoft still ships it with Visual Studio and fixes bugs, but it does not receive the modern UI features, DPI/accessibility improvements, or XAML-based styling investment that WPF and WinUI 3 receive. Starting a brand-new consumer-facing UI in MFC in 2026 is rarely the right call.
- MFC is a C++ class library, shipped with Visual Studio since 1992, that wraps the Win32 API in object-oriented classes.
- It eliminates the need to hand-write RegisterClass/CreateWindow calls and giant WM_ message switch statements.
- CObject provides RTTI and serialization; CWnd wraps HWNDs; CWinApp owns the single application instance and message pump.
- CDocument and CView implement the Document/View architecture that separates data from presentation.
- MFC remains a sound choice for maintaining existing native Windows desktop codebases.
- For new greenfield projects, WPF, WinUI 3, or Qt are generally evaluated before MFC today.
- MFC is in maintenance mode - stable but not a focus of new Microsoft UI investment.
Practice what you learned
1. What is the primary purpose of MFC?
2. Which class represents the single running instance of an MFC application and owns the message pump?
3. What capability does CObject provide to most classes in the MFC hierarchy?
4. Before MFC, how did developers typically handle window messages in raw Win32 C code?
5. For which scenario is MFC generally still considered a reasonable choice today?
Was this page helpful?
You May Also Like
MFC vs Win32 API
A comparison of programming directly against the raw Win32 API versus using MFC's object-oriented abstraction layer, covering trade-offs in productivity, control, and code size.
MFC Application Architecture
How an MFC application is structured around CWinApp, message maps, and frame windows, and how these pieces cooperate to start up, route input, and shut down cleanly.
MFC Project Structure
A tour of the files a Visual Studio MFC project generates - source, resource, and precompiled-header files - and how the build configuration ties them together.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics
Microsoft TechnologiesMVVM Design Pattern Study Notes
.NET · 30 topics