Delen via


CWinApp: The Application Class

The main application class in MFC encapsulates the initialization, running, and termination of an application for the Windows operating system. An application built on the framework must have one and only one object of a class derived from CWinApp. This object is constructed before windows are created.

CWinApp is derived from CWinThread, which represents the main thread of execution for your application, which might have one or more threads. In recent versions of MFC, the InitInstance, Run, ExitInstance, and OnIdle member functions are actually in class CWinThread. These functions are discussed here as if they were CWinApp members instead, because the discussion concerns the object's role as application object rather than as primary thread.

Note

Your application class constitutes your application's primary thread of execution. Using Win32 API functions, you can also create secondary threads of execution. These threads can use the MFC Library. For more information, see Multithreading.

Like any program for the Windows operating system, your framework application has a WinMain function. In a framework application, however, you do not write WinMain. It is supplied by the class library and is called when the application starts up. WinMain performs standard services such as registering window classes. It then calls member functions of the application object to initialize and run the application. (You can customize WinMain by overriding the CWinApp member functions that WinMain calls.)

To initialize the application, WinMain calls your application object's InitApplication and InitInstance member functions. To run the application's message loop, WinMain calls the Run member function. On termination, WinMain calls the application object's ExitInstance member function.

Note

Names shown in bold in this documentation indicate elements supplied by the Microsoft Foundation Class Library and Visual C++. Names shown in monospaced type indicate elements that you create or override.

See Also

Concepts

General MFC Topics

CWinApp and the MFC Application Wizard

Overridable CWinApp Member Functions

Special CWinApp Services