To make your application class available and accessible to the objects of your application, you must declare a global variable from it and there must be only one variable of your application. This variable is of the type of the class derived from CWinApp. Here is an example:
class CSimpleApp : public CWinApp
{
};
CSimpleApp MyApplication;
As you can see, you can name this global variable anything you want. By tradition, in Microsoft Visual C++, this variable is named theApp. Here is an example:
CSimpleApp theApp;
To get a pointer to this variable from anywhere in your application, call the AfxGetApp() framework 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.
Comments
Post a Comment