13.2 Deriving Classes from CWinApp

The Microsoft Foundation class CWinApp provides much of the framework of a basic Windows application. You will typically not need to change very much of this functionality except for the initialization parts. The following six member functions of CWinApp are designed to be overridden in derived classes. You will almost always override InitInstance. The other functions can be overridden as needed to provide special processing beyond the default behavior.

CWinApp function Purpose When to override

InitApplication One-time application initialization Seldom
InitInstance Creates main window Almost always
Run Message loop Seldom
PreTranslateMessage Extra message processing Seldom
OnIdle Idle loop processing If needed to perform background tasks when no messages are pending
ExitInstance Called when program terminates, returns exit code to Windows Sometimes, to perform application cleanup