다음을 통해 공유


CWinApp::InitInstance

Windows 동시에 실행 하는 동일한 프로그램의 여러 복사본을 수 있습니다.

virtual BOOL InitInstance( );

반환 값

초기화에 성공 하면 0이 아닌. 그렇지 않으면 0입니다.

설명

응용 프로그램 초기화 두 섹션으로 개념적으로 나뉩니다: 첫 번째 수행 되는 일회성 응용 프로그램 초기화 시간에 프로그램이 실행 될 및 각 실행 인스턴스 초기화 시간 복사본의 처음을 포함 하 여 프로그램 실행.프레임 워크의 구현 WinMain 이 함수를 호출 합니다.

재정의 InitInstance 각 Windows에서 실행 중인 응용 프로그램의 새 인스턴스를 초기화 합니다.일반적으로 재정의 하 여 InitInstance 주 창 개체를 생성 하 고 설정 하는 CWinThread::m_pMainWnd 이 창으로 가리키도록 데이터 멤버입니다.이 멤버 함수를 재정의 대 한 자세한 내용은 CWinApp: 응용 프로그램 클래스의.

[!참고]

단일 스레드 아파트 (STA) MFC 응용 프로그램을 초기화 해야 합니다.호출 하는 경우 CoInitializeExInitInstance 재정의 하 고 지정 COINIT_APARTMENTTHREADED (아니라 COINIT_MULTITHREADED).자세한 내용은 PRB: MFC 응용 프로그램 응답 응용 프로그램은 다중 스레드 아파트 (828643)를 초기화할 때 https://support.microsoft.com/default.aspx?scid=kb;en-us;828643.

예제

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

BOOL CMFCListViewApp::InitInstance()
{
   AfxSetAmbientActCtx(FALSE);
   // Remainder of function definition omitted.

   CWinApp::InitInstance();

   // Initialize OLE libraries
   if (!AfxOleInit())
   {
      AfxMessageBox(_T("OleInit failed."));
      return FALSE;
   }

   // 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
   // Change the registry key under which our settings are stored
   // TODO: You should modify this string to be something appropriate
   // such as the name of your company or organization
   SetRegistryKey(_T("Local AppWizard-Generated Applications"));
   LoadStdProfileSettings(4);  // 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
   CMultiDocTemplate* pDocTemplate;
   pDocTemplate = new CMultiDocTemplate(IDR_MFCListViewTYPE,
      RUNTIME_CLASS(CMFCListViewDoc),
      RUNTIME_CLASS(CChildFrame), // custom MDI child frame
      RUNTIME_CLASS(CMyListView));
   if (!pDocTemplate)
      return FALSE;
   AddDocTemplate(pDocTemplate);

   // create main MDI Frame window
   CMainFrame* pMainFrame = new CMainFrame;
   if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
   {
      delete pMainFrame;
      return FALSE;
   }
   m_pMainWnd = pMainFrame;
   // call DragAcceptFiles only if there's a suffix
   //  In an MDI app, this should occur immediately after setting m_pMainWnd


   // Parse command line for standard shell commands, DDE, file open
   CCommandLineInfo cmdInfo;
   ParseCommandLine(cmdInfo);


   // Dispatch commands specified on the command line.  Will return FALSE if
   // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
   if (!ProcessShellCommand(cmdInfo))
      return FALSE;
   // The main window has been initialized, so show and update it
   pMainFrame->ShowWindow(m_nCmdShow);
   pMainFrame->UpdateWindow();

   return TRUE;
}

요구 사항

헤더: afxwin.h

참고 항목

참조

CWinApp 클래스

계층 구조 차트