Breyta

Deila með


Creating an MFC Application

An MFC application is an executable application for Windows that is based on the Microsoft Foundation Class (MFC) Library. MFC executables generally fall into five types: standard Windows applications, dialog boxes, forms-based applications, Explorer-style applications, and Web browser-style applications. For more information, see:

The MFC Application Wizard generates the appropriate classes and files for any of these types of applications, depending on the options you select in the wizard.

The easiest way to create an MFC application is to use the MFC Application Wizard (MFC App project in Visual Studio 2019). To create an MFC console application (a command-line program that uses MFC libraries but runs in the console window), use the Windows Desktop Wizard and choose the Console Application and MFC Headers options.

To create an MFC forms or dialog-based application

  1. From the main menu, choose File > New > Project.
  2. Enter "MFC" into the search box and then choose MFC App from the result list.
  3. Modify the defaults as needed, then press Create to open the MFC Application Wizard.
  4. Modify the configuration values as needed, then press Finish.

For more information, see Creating a forms-based MFC application.

Screenshot of the MFC Application wizard in Visual Studios 2022.

The dialog shows options for the application type, which is set to single document. Application type options include tabbed documents, which is checked, and document/view architecture support, which is checked. There are other options for project style, resource language, and so on, that are set to their default values.

To create an MFC console application

An MFC console application is a command-line program that uses MFC libraries but runs in the console window.

  1. From the main menu, choose File > New > Project.
  2. Enter "Desktop" into the search box and then choose Windows Desktop Wizard from the result list, then press Next.
  3. Modify the project name and location as needed, then press Create to open the Windows Desktop Wizard.
  4. Check the MFC Headers box and set other values as needed, then press OK.

Screenshot of the Windows Desktop Project wizard in Visual Studios 2022.

The dialog shows the application type, set to Console Application (.exe). Under Additional Options, Precompiled header is checked as is MFC headers. Precompiled header is checked automatically when MFC headers is checked.

To create an MFC forms or dialog-based application

  1. From the Visual Studio main menu, choose File > New > Project.
  2. Under the Installed templates, choose Visual C++ > MFC/ATL. If you don't see these, use the Visual Studio Installer to add MFC/ATL functionality. You can access the installer from the Visual Studio menu via Tools > Get Tools and Features... In the installer, select Individual components and search for mfc and then select the appropriate library for your machine such as Visual C++ MFC for x86 and x64 with Spectre Mitigations.
  3. Choose MFC App from the center pane.
  4. Modify the configuration values as needed, then press OK.

For more information, see Creating a Forms-Based MFC Application.

Screenshot of the MFC Application wizard in Visual Studios 2017.

The dialog shows the various settings set to their default, such as the application type set to console application.exe; precompiled header is checked and security development lifecycle (SDL) is checked. Add common headers for: MFC isn't checked, but you select it.

To create an MFC console application

An MFC console application is a command-line program that uses MFC libraries but runs in the console window.

  1. From the main menu, choose File > New > Project.
  2. Under the Installed templates, choose Visual C++ > Windows Desktop.
  3. From the center pane, choose Windows Desktop Wizard.
  4. Modify the project name as needed, then press OK to open the Windows Desktop Wizard.
  5. Check the MFC Headers box and set other values as needed, then press OK.

Screenshot of the Windows Desktop Project wizard in Visual Studios 2017.

The dialog shows the application type set to Console Application (.exe). Under additional options, Precompiled header is checked and MFC headers is checked.

To create an MFC forms or dialog-based application

  1. From the main menu, choose File > New > Project.
  2. Under the Installed templates, choose Visual C++ > MFC.
  3. Choose MFC Application from the center pane.
  4. Click Next to start the MFC Application Wizard.

For more information, see Creating a Forms-Based MFC Application.

Screenshot of the MFC Application wizard in Visual Studios 2015.

The dialog lists the current project settings such as: tabbed multiple document interface, no database support, no compound document support, customizable menu bar and toolbar interface, Visual Studio 2008 application appearance, Visual Studio project style, and restart manager support.

To create an MFC console application

An MFC console application is a command-line program that uses MFC libraries but runs in the console window.

  1. From the main menu, choose File > New > Project.
  2. Under the Installed templates, choose Visual C++ > Win32.
  3. Choose Win32 Console Application from the center pane.
  4. Modify the project name as needed, then press OK.
  5. On the second page of the wizard, check the Add common headers for MFC box and set other values as needed, then press Finish.

Once your project is created, you can view the files created in Solution Explorer. For more information about the files the wizard creates for your project, see the project-generated file ReadMe.txt. For more information about the file types, see File Types Created for Visual Studio C++ projects.

See also

Adding Functionality with Code Wizards
Property Pages