Udostępnij za pośrednictwem


InitInstance Member Function

The Windows operating system allows you to run more than one copy, or "instance," of the same application. WinMain calls InitInstance every time a new instance of the application starts.

The standard InitInstance implementation created by the MFC Application Wizard performs the following tasks:

  • As its central action, creates the document templates that in turn create documents, views, and frame windows. For a description of this process, see Document Template Creation.

  • Loads standard file options from an .ini file or the Windows registry, including the names of the most recently used files.

  • Registers one or more document templates.

  • For an MDI application, creates a main frame window.

  • Processes the command line to open a document specified on the command line or to open a new, empty document.

You can add your own initialization code or modify the code written by the wizard.

Note

MFC applications must be initialized as single threaded apartment (STA). If you call CoInitializeEx in your InitInstance override, specify COINIT_APARTMENTTHREADED (rather than COINIT_MULTITHREADED). For more information, see PRB: MFC Application Stops Responding When You Initialize the Application as a Multithreaded Apartment (828643) at https://support.microsoft.com/default.aspx?scid=kb;en-us;828643.

See Also

Concepts

CWinApp: The Application Class