Share via


CWinApp::InitInstance

This method initializes an instance of an application. Windows CE allows several copies of the same program to run at the same time. Application initialization is conceptually divided into two sections: one-time application initialization that is done the first time the program runs, and instance initialization that runs each time a copy of the program runs, including the first time. The implementation of WinMain in the framework calls this method.

Override InitInstance to initialize each new instance of your application running under Windows CE. Typically, you override InitInstance to construct your main window object and set the CWinThread::m_pMainWnd data member to point to that window.

virtual BOOL InitInstance( ); 

Return Value

Nonzero if initialization is it is successful; otherwise, it is zero.

Example

// AppWizard implements the InitInstance overridable function
// according to options you select. For example, the single document
// interface (SDI) option was chosen for the AppWizard code created
// below. You can add other per-instance initializations to the code
// created by AppWizard.

BOOL CMyApp::InitInstance()
{
   // Standard initialization.
   // If you are not using these features and wish to reduce the size
   //  of your final executable, you should remove from the following
   //  the specific initialization routines you do not need.

   SetDialogBkColor();        // Set dialog background color to gray.
   LoadStdProfileSettings();  // Load standard .ini file options
   // (including MRU).

   // Register the application's document templates. Document templates
   //  serve as the connection between documents, frame windows and views.

   CSingleDocTemplate* pDocTemplate;
   pDocTemplate = new CSingleDocTemplate(
      IDR_MAINFRAME,
      RUNTIME_CLASS(CMyDoc),
      RUNTIME_CLASS(CMainFrame),     // main SDI frame window
      RUNTIME_CLASS(CMyView));
   AddDocTemplate(pDocTemplate);

   // Create a new (empty) document.
   OnFileNew();

   if (m_lpCmdLine[0] != '\0')
   {
      // TODO: Add command line processing here.
   }

   return TRUE;
}

Requirements

**  Windows CE versions:** 1.0 and later
  Header file: Declared in Afxwin.h
  Platform: H/PC Pro, Palm-size PC, Pocket PC

See Also

CWinApp::InitApplication