共用方式為


CWinApp Class

The base class from which you derive a Windows application object.

class CWinApp : public CWinThread

Remarks

An application object provides member functions for initializing your application (and each instance of it) and for running the application.

Each application that uses the Microsoft Foundation classes can only contain one object derived from CWinApp. This object is constructed when other C++ global objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the Microsoft Foundation Class Library. Declare your derived CWinApp object at the global level.

When you derive an application class from CWinApp, override the InitInstance member function to create your application's main window object.

In addition to the CWinApp member functions, the Microsoft Foundation Class Library provides the following global functions to access your CWinApp object and other global information:

  • AfxGetApp   Obtains a pointer to the CWinApp object.

  • AfxGetInstanceHandle   Obtains a handle to the current application instance.

  • AfxGetResourceHandle   Obtains a handle to the application's resources.

  • AfxGetAppName   Obtains a pointer to a string containing the application's name. Alternately, if you have a pointer to the CWinApp object, use m_pszExeName to get the application's name.

See CWinApp: The Application Class for more on the CWinApp class, including an overview of the following:

  • CWinApp-derived code written by the Application Wizard.

  • CWinApp's role in the execution sequence of your application.

  • CWinApp's default member function implementations.

  • CWinApp's key overridables.

The m_hPrevInstance data member no longer exists. For information on detecting a previous instance of CWinApp, see the Knowledge Base article "How To Identify a Previous Instance of an Application" (KB106385) at https://support.microsoft.com/default.aspx?scid=kb;en-us;106385.

Requirements

Header: afxwin.h

See Also

Tasks

How to: Add Restart Manager Support

Reference

CWinThread Class

Hierarchy Chart

Other Resources

CWinApp Members