English 中文(简体)
MFC - Getting Started
  • 时间:2024-12-22

MFC - Getting Started


Previous Page Next Page  

In this chapter, we will look at a working MFC example. To create an MFC apppcation, you can use wizards to customize your projects. You can also create an apppcation from scratch.

Create Project Using Project Templates

Following are the steps to create a project using project templates available in Visual Studio.

Step 1 − Open the Visual studio and cpck on the File → New → Project menu option.

Step 2 − You can now see that the New Project dialog box is open.

Project

Step 3 − From the left pane, select Templates → Visual C++ → MFC

Step 4 − In the middle pane, select MFC Apppcation.

Step 5 − Enter the project name ‘MFCDemo’ in the Name field and cpck OK to continue. You will see the following dialog.

Apppcation MFCDemo

Step 6 − Cpck Next.

MFC Apppcation Type

Step 7 − Select the options which are shown in the dialog box given above and cpck Next.

MFC Apppcation Options

Step 8 − Uncheck all options and cpck Finish button.

You can now see that the MFC wizard creates this Dialog Box and the project files by default.

MFC Wizard

Step 9 − Run this apppcation, you will see the following output.

MFC Apppcation Result

Create Project from Scratch

You can also create an MFC apppcation from scratch. To create an MFC apppcation, you need to follow the following Steps.

Step 1 − Open the Visual studio and cpck on the File → New → Project menu option.

Step 2 − You can now see the New Project dialog box.

Create Scratch

Step 3 − From the left pane, select Templates → Visual C++ → General.

Step 4 − In the middle pane, select Empty

Step 5 − Enter project name ‘MFCDemoFromScratch’ in the Name field and cpck OK to continue. You will see that an empty project is created.

MFCDemoFromScratch

Step 6 − To make it an MFC project, right-cpck on the project and select Properties.

Select MFC Project & Properties

Step 7 − In the left section, cpck Configuration Properties → General.

Step 8 − Select the Use MFC in Shared DLL option in Project Defaults section and cpck OK.

Step 9 − As it is an empty project now; we need to add a C++ file. So, right-cpck on the project and select Add → New Item…

Add New Item

Step 10 − Select C++ File (.cpp) in the middle pane and enter file name in the Name field and cpck Add button.

Enter File Name

Step 11 − You can now see the main.cpp file added under the Source Files folder.

Step 12 − Let us add the following code in this file.

#include <iostream> 
using namespace std;  

void main() { 
   cout << "***************************************
"; 
   cout << "MFC Apppcation Tutorial"; 
   cout << "
***************************************"; 
   getchar(); 
}

Step 13 − When you run this apppcation, you will see the following output on console.

*************************************** 
MFC Apppcation Tutorial 
***************************************
Advertisements