Mfc Application Tutorial

This MFC Tutorial example creates a simple Window with a title called “MFC Tutorial Part 1 CoderSource Window”. The window has no contents, menu or any other controls. The next part of this MFC Tutorial series will handle the left out topics one by one. This is an application that relies on the MFC's file processing to process customers' orders for a car repair business. College Park Auto-Shop: This is a Microsoft SQL Server Desktop Database (MSDE) database used in an MFC application. The connection is done through an ODBC Data Source. An MFC console application is a command-line program that uses MFC libraries but runs in the console window. From the main menu, choose File New Project. Enter 'Desktop' into the search box and then choose Windows Desktop Wizard from the result list. Modify the project name as needed, then press Next to open the Windows Desktop Wizard.

8 Mar 2004
This article explains how to create a window in MFC without using the App Wizard. It uses only two classes, CFrameWnd and CWinApp, for creating the window.

Introduction

MFC provides really nice classes for doing Windows programming. It has taken away all the pains of SDK, where a programmer is expected to handle everything in the world except writing application logic.

Creating a Window using MFC

The first task to be done in any application is to create a window for an application. MFC provides two important classes viz. CWinApp and CFrameWnd, which can be used for creating a window and the application. Both these classes have their own message handling mechanisms, screen-drawing functions etc. To be precise, CWinApp provides the application level functionalities, and CFrameWnd provides the functionalities related to GUI.

All these classes are derived from CCmdTarget which in turn is derived from CObject. CCmdTarget is created with the capability to handle Windows messages, which is referred to as Message Maps. If you wonder what this Message map means, 'Message maps are macros which take care of the event handling'.

The CWinApp class has an important over-ridable function, InitInstance, which handles the window creations. The next important one is a data member, m_pMainWnd (of CWinApp) which holds the pointer to the window.

Let's write an example and try to understand it. Follow these steps to create an application with minimal usage wizard. The wizard will be used just to create a simple workspace for this MFC tutorial.

Step1:

Create a new project of type Win32 application. In the second screen of the wizard, select the first option. Do not allow the wizard to add any files. Just choose Empty project.

Step 2:

After the project is created, click on Menu -->Project --> Add to Project -->New and select a .cpp file and give a name to it.

Step 3:

Copy and paste the code below:

Step 4:

Mfc

Now, compile the application. It will generate linker errors. The reason is because the MFC libraries are not yet linked.

Do the last step of this MFC tutorial.

Step 5:

Select Menu -->Project --> Settings and General tab. On the first combo box, 'Microsoft Foundation classes', and select 'Use MFC in shared DLL'.

Now, compile and run the program.

Mfc

This MFC tutorial example creates a simple window with a title called 'MFC Tutorial Part 1 CoderSource Window'. The window has no contents, menu, or any other controls.

This tutorial is a very simple illustration of how to create a window using MFC.

Note: This article an also be found at Codersource MFC Tutorial 1. The codersource website belongs to this author.

Download Code

Creating a Simple SDI Application

Mfc Application Wizard Tutorial

This MFC video tutorial demonstrates how to make a simple GUI application. MFC stands for Microsoft Foundation Classes and is a C++ class library, which wraps the Win32 API (Application Programming Interface) in a cleaner, simpler form. SDI stands for Single Document Interface, which we will explain more when we talk about the architecture of MFC applications.

For this lesson, and to create MFC applications in general, you need to have Microsoft's Visual C++ or Visual Studio Standard Edition or higher (Professional or Enterprise). MFC is not available in the free Express Editions.

Tutorial

Visual C++ Mfc Application Tutorial


  1. Open Visual Studio. Go to the 'File' menu, mouse over 'New', and then left-click 'Project' in the submenu. This will open the 'New Project' dialog.
  2. In the dialog, open the 'Visual C++' section in the 'Project Types' box and select 'MFC'. Then in the right area window, left-click 'MFC Application'. Next, rename the lesson 'Lesson1.' Finally, select a location for the project by using the 'Browse' button and click the 'OK' button when you are done.
  3. This will start the 'MFC Application Wizard.' Left-click 'Application Type' in the left-hand area. Next, select the radio button next to 'Single document' under 'Application type:'. Then, select the radio button next to 'Use MFC in a static library' under 'Use of MFC:'. Finally, click the 'Finish' button to create the project.
  4. Now, to compile and execute the program: left-click 'Debug' in the menubar and then left-click 'Start Without Debugging'.
  5. This will pop up a message box to ask whether you would like to build the program. Click the 'Yes' button.
  6. When the program finishes compiling and runs, you will see a window entitled 'Untitled - Lesson1.' This window is the SDI application that was created.