News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Introduction to MFC -VC++

Started by sukishan, Jul 12, 2009, 05:07 PM

Previous topic - Next topic

sukishan

Introduction to MFC

Introduction to Applications

The Microsoft Foundation Class (MFC) library is a set of data types, functions, classes, and constants used to create applications for the Microsoft Windows family of operating systems.

The first thing you should do to start a program is to create an application. In Win32, an application is created by a call to the WinMain() function and building a WNDCLASS or WNDCLASSEX structure. In MFC, this process has been resumed in a class called CWinApp (Class-For-A-Windows-Application). Based on this, to create an application, you must derive your own class from CWinApp.

An application by itself is an empty thing that only lets the operating system know that you are creating a program that will execute on the computer. It doesn't display anything on the screen. If you want to display something, the CWinApp class provides the InitApplication() method that you must override in your class. InitApplication() is a Boolean method. If it succeeds in creating the application, it returns TRUE. If something went wrong when trying to create the application, it would return FALSE. The minimum skeleton of an application would appear as follows:

class CExerciseApp : public CWinApp
{
public:
    virtual BOOL InitInstance();
};

BOOL CExerciseApp::InitInstance()
{
    return TRUE;
}


After creating the application, to make it available to other parts of the program, you must declare a global variable of your class. It is usually called theApp but you can call it anything you want.

The fundamental classes of MFC are declared in the afxwin.h header file. Therefore, this is the primary header you may have to add to each one of your applications. Based on this, a basic application can be created as follows:

#include <AFXWIN.H>

class CExerciseApp : public CWinApp
{
public:
    virtual BOOL InitInstance();
};

BOOL CExerciseApp::InitInstance()
{
    return TRUE;
}

CExerciseApp theApp;
A good beginning makes a good ending