Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows
10.1.2..The Framework....................................................................................
Instead of creating an application using "raw" Win32 classes and functions, the
document/view architecture simplifies this process by providing a mechanism called the
framework. The framework is a set of classes, functions, and techniques used to create an
application as complete as possible with as few lines of code as possible. To provide all
this functionality, the framework works behind the scenes with the CWinApp class to
gather the necessary MFC classes and functions, to recognize and reconcile the Win32
classes that the application needs. This reconciliation is also made possible by a set of
global functions. These functions have names that start with Afx... Some of these
functions are:
?? AfxFormatString1
?? AfxFormatString2
?? AfxMessageBox
?? AfxFreeLibrary
?? AfxGetApp
?? AfxGetAppName
?? AfxGetInstanceHandle
?? AfxGetMainWnd
?? AfxGetResourceHandle
?? AfxInitRichEdit
?? AfxLoadLibrary
?? AfxMessageBox
?? AfxRegisterWndClass
?? AfxSocketInit
?? AfxSetResourceHandle
?? AfxRegisterClass
?? AfxBeginThread
?? AfxEndThread
?? AfxGetThread
?? AfxWinInit
So far, we have seen that, after an application is created by deriving a class from
CWinApp, you must declare a global variable of your application class to make it
available to the rest of your application. An example of declaring that variable is:
CExerciseApp theApp;
To get a pointer to this variable from anywhere in your application, call the AfxGetApp()
function. Its syntax is:
CWinApp* AfxGetApp();
To implement the role of the Win32's WinMain() function, the framework uses its own
implementation of this function and the MFC provides it as AfxWinInit(). It is declared
as follows:
BOOL AFXAPI AfxWinInit(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow);
As you can see, the Win32's WinMain() and the MFC's AfxWinInit() functions use the
same arguments.