//------------------------------------------------------------------ // main //------------------------------------------------------------------ void main() { CWinApp* pApp = AfxGetApp(); pApp->InitApplication(); pApp->InitInstance(); pApp->Run(); CMyDoc* pMyDoc = new CMyDoc; CMyView* pMyView = new CMyView; CFrameWnd* pMyFrame = (CFrameWnd*)pApp->m_pMainWnd; // output Message Map construction AFX_MSGMAP* pMessageMap = pMyView->GetMessageMap(); cout << endl << "CMyView Message Map : " << endl; MsgMapPrinting(pMessageMap); pMessageMap = pMyDoc->GetMessageMap(); cout << endl << "CMyDoc Message Map : " << endl; MsgMapPrinting(pMessageMap); pMessageMap = pMyFrame->GetMessageMap(); cout << endl << "CMyFrameWnd Message Map : " << endl; MsgMapPrinting(pMessageMap); pMessageMap = pApp->GetMessageMap(); cout << endl << "CMyWinApp Message Map : " << endl; MsgMapPrinting(pMessageMap); }
//------------------------------------------------------------------ // main //------------------------------------------------------------------ void main() { CWinApp* pApp = AfxGetApp(); pApp->InitApplication(); pApp->InitInstance(); pApp->Run(); CMyDoc* pMyDoc = new CMyDoc; CMyView* pMyView = new CMyView; CWnd* pMyWnd = pApp->m_pMainWnd; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CMyDoc)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CMyDoc)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CDocument)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CDocument)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CCmdTarget)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CCmdTarget)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CObject)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CObject)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CWinApp)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CWinApp)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CView)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CView)) << "\n"; cout << "pMyView->IsKindOf(RUNTIME_CLASS(CView)) " << pMyView->IsKindOf(RUNTIME_CLASS(CView)) << "\n"; cout << "pMyView->IsKindOf(RUNTIME_CLASS(CObject)) " << pMyView->IsKindOf(RUNTIME_CLASS(CObject)) << "\n"; cout << "pMyView->IsKindOf(RUNTIME_CLASS(CWnd)) " << pMyView->IsKindOf(RUNTIME_CLASS(CWnd)) << "\n"; cout << "pMyView->IsKindOf(RUNTIME_CLASS(CFrameWnd)) " << pMyView->IsKindOf(RUNTIME_CLASS(CFrameWnd)) << "\n"; cout << "pMyWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)) " << pMyWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)) << "\n"; cout << "pMyWnd->IsKindOf(RUNTIME_CLASS(CWnd)) " << pMyWnd->IsKindOf(RUNTIME_CLASS(CWnd)) << "\n"; cout << "pMyWnd->IsKindOf(RUNTIME_CLASS(CObject)) " << pMyWnd->IsKindOf(RUNTIME_CLASS(CObject)) << "\n"; cout << "pMyWnd->IsKindOf(RUNTIME_CLASS(CDocument)) " << pMyWnd->IsKindOf(RUNTIME_CLASS(CDocument)) << "\n"; }
int main(void) { CWinApp* pApp = AfxGetApp(); pApp->InitApplication(); pApp->InitInstance(); pApp->Run(); CMyDoc* pMyDoc = new CMyDoc; CMyView* pMyView = new CMyView; CFrameWnd* pMyFrame = (CFrameWnd*)pApp->m_pMainWnd; pMyFrame->m_pViewActive = pMyView; pMyView->m_pDocument = pMyDoc; std::cout << std::endl << "pMyFrame received a WM_CREATE, routing path : " << std::endl; AfxWndProc(0, WM_CREATE, 0, 0, pMyFrame); std::cout << std::endl << "pMyView received a WM_COMMAND, routing path : " << std::endl; AfxWndProc(0, WM_COMMAND, 0, 0, pMyView); std::cout << std::endl << "pMyFrame received a WM_COMMAND, routing path : " << std::endl; AfxWndProc(0, WM_COMMAND, 0, 0, pMyFrame); system("pause"); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { app.InitInstance( hInstance, szCmdLine, iCmdShow ); app.Run(); return app.ExitInstance(); }//WinMain()
void main() { CWinApp *pApp = AfxGetApp(); pApp->InitApplication(); pApp->InitInstance(); pApp->Run(); PrintAllClasses(); }
int main() { cout << "main 開始執行" << endl; CWinApp* pApp = AfxGetApp(); pApp->InitApplication(); //CWinApp::InitApplication pApp->InitInstance(); //CMyWinApp::InitInstance --> CMyFrameWnd pApp->Run(); //CwinApp::Run cout << "main 結束執行" << endl; return 0; }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { AfxWinInit(hInst, hPrevInst, lpCmdLine, nCmdShow); CWinApp* pApp = AfxGetApp(); if ( ! pApp->InitInstance()) { return 1; } int result = pApp->Run(); pApp->ExitInstance(); return result; }
extern "C" int WINAPI #endif WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { ASSERT(hPrevInstance == NULL); lpCmdLine; int nReturnCode = -1; CWinApp* pApp = AfxGetApp(); // AFX internal initialization LPTSTR p = GetCommandLine(); while (*p && (*p != _T(' '))) p++; if (*p) p++; if (!AfxWinInit(hInstance, hPrevInstance, p, nCmdShow)) goto InitFailure; // App global initializations (rare) ASSERT_VALID(pApp); if (!pApp->InitApplication()) goto InitFailure; ASSERT_VALID(pApp); // Perform specific initializations if (!pApp->InitInstance()) { if (pApp->m_pMainWnd != NULL) { TRACE0("Warning: Destroying non-NULL m_pMainWnd\n"); pApp->m_pMainWnd->DestroyWindow(); } nReturnCode = pApp->ExitInstance(); goto InitFailure; } ASSERT_VALID(pApp); nReturnCode = pApp->Run(); ASSERT_VALID(pApp); InitFailure: AfxWinTerm(); return nReturnCode; }
int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) /**********************************/ { if( !AfxWinInit( hInstance, hPrevInstance, lpCmdLine, nCmdShow ) ) { return( -1 ); } AfxInitThread(); CWinApp *pApp = AfxGetApp(); ASSERT( pApp != NULL ); int nExitCode; if( !pApp->InitInstance() ) { nExitCode = -1; } else { nExitCode = pApp->Run(); } AfxTermThread( hInstance ); return( nExitCode ); }
int main() { CWinApp* pApp = AfxGetApp(); if (pApp->InitInstance()) pApp->Run(); pApp->ExitInstance(); }
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { char szLogFileName[_MAX_DIR]; if (GetRecommandLogFileName(szLogFileName) == false) return FALSE; InitLog(MLOGSTYLE_DEBUGSTRING|MLOGSTYLE_FILE, szLogFileName); // Wrap WinMain in a structured exception handler (different from C++ // exception handling) in order to make sure that all access violations // and other exceptions are displayed - regardless of when they happen. // This should be done for each thread, if at all possible, so that exceptions // will be reliably caught, even inside the debugger. #ifdef SUPPORT_EXCEPTIONHANDLING char szDumpFileName[_MAX_DIR]; strcpy(szDumpFileName, szLogFileName); strcat(szDumpFileName, ".dmp"); __try { #endif // The code inside the __try block is the MFC version of AfxWinMain(), // copied verbatim from the MFC source code. ASSERT(hPrevInstance == NULL); int nReturnCode = -1; CWinApp* pApp = AfxGetApp(); // AFX internal initialization if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) goto InitFailure; // App global initializations (rare) ASSERT_VALID(pApp); if (!pApp->InitApplication()) goto InitFailure; ASSERT_VALID(pApp); // Perform specific initializations if (!pApp->InitInstance()) { if (pApp->m_pMainWnd != NULL) { TRACE(_T("Warning: Destroying non-NULL m_pMainWnd\n")); pApp->m_pMainWnd->DestroyWindow(); } nReturnCode = pApp->ExitInstance(); goto InitFailure; } ASSERT_VALID(pApp); nReturnCode = pApp->Run(); ASSERT_VALID(pApp); InitFailure: #ifdef _DEBUG // Check for missing AfxLockTempMap calls if (AfxGetModuleThreadState()->m_nTempMapLock != 0) { TRACE(_T("Warning: Temp map lock count non-zero (%ld).\n"), AfxGetModuleThreadState()->m_nTempMapLock); } AfxLockTempMaps(); AfxUnlockTempMaps(-1); #endif AfxWinTerm(); return nReturnCode; #ifdef SUPPORT_EXCEPTIONHANDLING } // __except(MFilterException(GetExceptionInformation())){ __except(CrashExceptionDump(GetExceptionInformation(), szDumpFileName)){ // char szFileName[_MAX_DIR]; // GetModuleFileName(NULL, szFileName, _MAX_DIR); // WinExec(szFileName, SW_SHOW); // Launch again //MMatchServer::GetInstance()->CheckMemoryTest(); //MGetServerStatusSingleton()->Dump(); } #endif return 0; }
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID) { CWinApp* pApp = AfxGetApp(); if (dwReason == DLL_PROCESS_ATTACH) { // initialize MFC exception handling #ifndef _AFX_OLD_EXCEPTIONS set_terminate(&AfxStandardTerminate); #endif _set_new_handler(&AfxNewHandler); // initialize DLL's instance(/module) not the app's if (!AfxWinInit(hInstance, NULL, &afxChNil, 0)) { AfxWinTerm(); return FALSE; // Init Failed } // initialize the single instance DLL if (pApp != NULL && !pApp->InitInstance()) { pApp->ExitInstance(); AfxWinTerm(); return FALSE; // Init Failed } } else if (dwReason == DLL_PROCESS_DETACH) { if (pApp != NULL) pApp->ExitInstance(); #ifdef _DEBUG // check for missing AfxLockTempMap calls if (AfxGetThreadState()->m_nTempMapLock != 0) TRACE1("Warning: Temp map lock count non-zero (%ld).\n", AfxGetThreadState()->m_nTempMapLock); #endif // terminate the library before destructors are called AfxWinTerm(); // free safety pool buffer AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); if (pThreadState->m_pSafetyPoolBuffer != NULL) { free(pThreadState->m_pSafetyPoolBuffer); pThreadState->m_pSafetyPoolBuffer = NULL; } #ifdef _DEBUG // trace any memory leaks that may have occurred AfxDumpMemoryLeaks(); #endif // clean up map objects before it is too late delete pThreadState->m_pmapHWND; pThreadState->m_pmapHWND = NULL; delete pThreadState->m_pmapHMENU; pThreadState->m_pmapHMENU = NULL; delete pThreadState->m_pmapHDC; pThreadState->m_pmapHDC = NULL; delete pThreadState->m_pmapHGDIOBJ; pThreadState->m_pmapHGDIOBJ = NULL; delete pThreadState->m_pmapHIMAGELIST; pThreadState->m_pmapHIMAGELIST = NULL; pThreadState->m_mapSocketHandle.CMapPtrToPtr::~CMapPtrToPtr(); pThreadState->m_mapDeadSockets.CMapPtrToPtr::~CMapPtrToPtr(); pThreadState->m_listSocketNotifications.CPtrList::~CPtrList(); } return TRUE; // ok }
int AFXAPI AfxWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { #ifdef DISPLAYCONSOLE // Redirection of standard output to console int hCrt; BOOL rep; FILE *hf; _SYSTEM_INFO lps; GetSystemInfo(&lps); rep = AllocConsole(); hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT); hf = _fdopen( hCrt, "w" ); *stdout = *hf; // stop the buffer on stdout // int i = setvbuf( stdout, NULL, _IONBF, 0 ); // filebuf ff(hCrt); // cout = &ff; cout<<"This Debug Window is defined in WinMain.cpp and will disappear in release mode"<<endl; #endif // DISPLAYCONSOLE // By Matra // create log file for all OCC messages // Message::DefaultMessenger()->AddPrinter (new Message_PrinterOStream ("OCCSampleRun.log", Standard_False)); ASSERT(hPrevInstance == NULL); int nReturnCode = -1; CWinApp* pApp = AfxGetApp(); // new in 2.0 CAS.CADE uses the standard C++ exception mechanism /*#ifdef _DEBUG // By Matra // _Function declaratiob here because you can jump to InitFailure Standard_ErrorHandler _Function; #endif // _DEBUG // By Matra */ // AFX internal initialization if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) goto InitFailure; // App global initializations (rare) ASSERT_VALID(pApp); if (!pApp->InitApplication()) goto InitFailure; ASSERT_VALID(pApp); // Perform specific initializations if (!pApp->InitInstance()) { if (pApp->m_pMainWnd != NULL) { TRACE0("Warning: Destroying non-NULL m_pMainWnd\n"); pApp->m_pMainWnd->DestroyWindow(); } nReturnCode = pApp->ExitInstance(); goto InitFailure; } ASSERT_VALID(pApp); #ifdef _DEBUG // By Matra Application: // new in 2.0 CAS.CADE uses the standard C++ exception mechanism // if(DoesNotAbort(_Function)) try { nReturnCode = pApp->Run(); } // if(_Function.Catches(STANDARD_TYPE(Standard_Failure))) catch(Standard_Failure) { Standard_SStream ostr; ostr<<Standard_Failure::Caught()<<"\n\0"; CString aMsg = ostr.str().c_str(); MessageBoxW (NULL, aMsg, L"CasCade Error", MB_ICONERROR); goto Application; // restart application loop } #else // _DEBUG // By Matra nReturnCode = pApp->Run(); #endif // _DEBUG // By Matra ASSERT_VALID(pApp); InitFailure: #ifdef _DEBUG // Check for missing AfxLockTempMap calls if (AfxGetModuleThreadState()->m_nTempMapLock != 0) { TRACE1("Warning: Temp map lock count non-zero (%ld).\n", AfxGetModuleThreadState()->m_nTempMapLock); } AfxLockTempMaps(); AfxUnlockTempMaps(); #endif AfxWinTerm(); #ifdef DISPLAYCONSOLE // By Matra // ferme la console pour le cout fclose( stdout ); //hCrt = _fcloseall(); :-) rep = FreeConsole(); #endif // DISPLAYCONSOLE // By Matra return nReturnCode; }