int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; // Generic message. HWND hWnd; // Main Window Handle. // Don't let more than one instance of the application exist // // NOTE: Comment out the following section of code if your game needs to have more // than one instance running on the same computer (i.e. client/server) //////////////////////////////////////////////////////////////////////// if (!hPrevInstance) { if (CheckIfAlreadyRunning()) return FALSE; } //////////////////////////////////////////////////////////////////////// // Register the window class if (!RegisterWindowClass(hInstance)) return 0; // Create the window hWnd = MakeWindow(hInstance); if (!hWnd) return 0; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); ////////////////////////////////////////// // Initialize Game here ////////////////////////////////////////// CGame* pGame = CGame::GetInstance(); pGame->Initialize( hWnd, hInstance, g_nWINDOW_WIDTH, g_nWINDOW_HEIGHT, g_bIS_WINDOWED ); ////////////////////////////////////////// // Enter main event loop while (TRUE) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Test if this is a quit if (msg.message == WM_QUIT) break; // Translate any accelerator keys TranslateMessage(&msg); // Send the message to the window proc DispatchMessage(&msg); } ////////////////////////////////// // Put Game Logic Here ////////////////////////////////// if( pGame->Main() == false ) PostQuitMessage(0); ////////////////////////////////// } ///////////////////////////////////////// // Shutdown Game Here ///////////////////////////////////////// pGame->Shutdown(); ///////////////////////////////////////// // Unregister the window class UnregisterClass(g_szWINDOW_CLASS_NAME, hInstance); // Return to Windows like this. return (int)(msg.wParam); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { srand((unsigned int)time(NULL)); ///////////////////////////////////////////// // Do any program wide Initialization here //_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //_CrtSetBreakAlloc(45755); ///////////////////////////////////////////// MSG msg; // Generic message. HWND hWnd; // Main Window Handle. // if in release mode set the exception filter to write out a dump file #ifndef _DEBUG SetUnhandledExceptionFilter(Handler); #endif // Don't let more than one instance of the application exist // // NOTE: Comment out the following section of code if your game needs to have more // than one instance running on the same computer (i.e. client/server) //////////////////////////////////////////////////////////////////////// if (!hPrevInstance) { if (CheckIfAlreadyRunning()) return FALSE; } //////////////////////////////////////////////////////////////////////// // Register the window class if (!RegisterWindowClass(hInstance)) return 0; // Create the window hWnd = MakeWindow(hInstance); if (!hWnd) return 0; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); ////////////////////////////////////////// // Initialize Game here ////////////////////////////////////////// CGame* pGame = CGame::GetInstance(); pGame->Initialize(hWnd,hInstance, g_nWINDOW_WIDTH, g_nWINDOW_HEIGHT, g_bIS_WINDOWED); ////////////////////////////////////////// // Enter main event loop while (TRUE) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Test if this is a quit if (msg.message == WM_QUIT) break; // Translate any accelerator keys TranslateMessage(&msg); // Send the message to the window proc DispatchMessage(&msg); } ////////////////////////////////// // Put Game Logic Here ////////////////////////////////// if(pGame->Main() == false) PostQuitMessage(0); ////////////////////////////////// } ///////////////////////////////////////// // Shutdown Game Here ///////////////////////////////////////// pGame->Shutdown(); ///////////////////////////////////////// // Unregister the window class UnregisterClass(g_szWINDOW_CLASS_NAME, hInstance); // Return to Windows like this. return (int)(msg.wParam); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; // Generic message. HWND hWnd; // Main Window Handle. #if _DUMP // if in release mode set the exception filter to write out a dump file #ifndef _DEBUG SetUnhandledExceptionFilter(Handler); #endif #endif // Don't let more than one instance of the application exist if (!hPrevInstance) { if (CheckIfAlreadyRunning()) return FALSE; } // Register the window class if (!RegisterWindowClass(hInstance)) return 0; // Create the window hWnd = MakeWindow(hInstance); if (!hWnd) return 0; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); #if _DEBUG /////////////////////////////////////////////////////////// //Allow console window for debuging //Code By: //http://justcheckingonall.wordpress.com/2008/08/29/console-window-win32-app/ /////////////////////////////////////////////////////////// AllocConsole(); HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE); int hCrt = _open_osfhandle((long) handle_out, _O_TEXT); FILE* hf_out = _fdopen(hCrt, "w"); setvbuf(hf_out, NULL, _IONBF, 1); *stdout = *hf_out; HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE); hCrt = _open_osfhandle((long) handle_in, _O_TEXT); FILE* hf_in = _fdopen(hCrt, "r"); setvbuf(hf_in, NULL, _IONBF, 128); *stdin = *hf_in; //////////////////////////////////////////////////////////// #endif ////////////////////////////////////////// // Initialize Game here ////////////////////////////////////////// //TODO: delete all of... CSGD_Direct3D* pD3D = CSGD_Direct3D::GetInstance(); pD3D->Initialize( hWnd, g_nWINDOW_WIDTH, g_nWINDOW_HEIGHT, g_bIS_WINDOWED, false ); CSGD_TextureManager::GetInstance()->Initialize( pD3D->GetDirect3DDevice(), pD3D->GetSprite() ); CSGD_DirectInput::GetInstance()->Initialize( hWnd, hInstance, DI_KEYBOARD | DI_MOUSE ); //...this Game cGameInstance; cGameInstance.Initialize(); pGamePtr = &cGameInstance; ////////////////////////////////////////// // Enter main event loop while (TRUE) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Test if this is a quit if (msg.message == WM_QUIT) break; // Translate any accelerator keys TranslateMessage(&msg); // Send the message to the window proc DispatchMessage(&msg); } ////////////////////////////////// // Put Game Logic Here ////////////////////////////////// cGameInstance.Run(); ////////////////////////////////// } ///////////////////////////////////////// // Shutdown Game Here ///////////////////////////////////////// cGameInstance.Shutdown(); ///////////////////////////////////////// // Unregister the window class UnregisterClass(g_szWINDOW_CLASS_NAME, hInstance); // Return to Windows like this. return (int)(msg.wParam); }