Featured image of post Microsoft Foundation Classes Cheatsheet

Microsoft Foundation Classes Cheatsheet

MFC Cheatsheet

ConceptSyntax/ExampleDescription
Application Classclass CMyApp : public CWinApp { ... };Defining an application class
Message MapBEGIN_MESSAGE_MAP(CMyWnd, CWnd) ... END_MESSAGE_MAP()Defining message map
Document/View Architectureclass CMyDoc : public CDocument { ... };Defining a document class
Dialog-Based Applicationclass CMyDlg : public CDialog { ... };Defining a dialog class
ControlsCButton myButton;Declaring a button control
GDI ObjectsCPen myPen;Declaring a GDI object
Event Handlingafx_msg void OnMyEvent();Handling an event
Serializationvoid Serialize(CArchive& ar);Implementing serialization
Windows Managementvoid ShowWindow(int nCmdShow);Managing windows
Resource ManagementAfxGetResourceHandle();Accessing resources

MFC Class Hierarchy Overview

plaintext

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
CObject
 ├── CCmdTarget
     ├── CWinThread
         ├── CWinApp
         └── CDocument
     └── CWnd
          ├── CFrameWnd
              └── CMDIFrameWnd
          ├── CMDIChildWnd
          ├── CDialog
          └── CView
 └── CArchive
  • CObject: The base class for all MFC classes.

  • CCmdTarget: Provides the ability to handle commands.

  • CWinThread: Represents a thread of execution in an MFC application.

    • CWinApp: Represents an application instance.

    • CDocument: Represents the data used by an application (part of the Document/View architecture).

  • CWnd: Represents a window.

    • CFrameWnd: Represents a frame window.

      • CMDIFrameWnd: Represents the main frame window in an MDI application.
    • CMDIChildWnd: Represents a child window in an MDI application.

    • CDialog: Represents a dialog box.

    • CView: Represents a view (part of the Document/View architecture).

  • CArchive: Provides support for serializing data to persistent storage.