/*********************** * WinMain: Main implementation of the class * @author: * @parameter: HINSTANCE _hInstance, instance * HINSTANCE _hPrevInstance, previous instance * LPSTR _lpCmdline, cmd line * int _iCmdshow, cmd show * @return: HWND ********************/ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE _hPrevInstance, LPSTR _lpCmdline, int _iCmdshow) { // Initialise msg MSG msg; ZeroMemory(&msg, sizeof(MSG)); srand((unsigned int)time(NULL)); g_hInstance = _hInstance; // Initialise width & height const int kiWidth = 835; const int kiHeight = 800; // Create window HWND hwnd = CreateAndRegisterWindow(_hInstance, kiWidth, kiHeight, "Space Invaders"); // Create game CGame& rGame = CGame::GetInstance(); // If game failed to initialise if (!rGame.Initialise(_hInstance, hwnd, kiWidth, kiHeight)) { // Failed return (0); } PlaySound(MAKEINTRESOURCE(IDR_WAVE1), NULL, SND_ASYNC | SND_RESOURCE | SND_LOOP ); // Main event loops // While the user has not quite while (msg.message != WM_QUIT) { // Do message things if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } // Otherwise play the game else { rGame.ExecuteOneFrame(); } } // Destory the game CGame::DestroyInstance(); return (static_cast<int>(msg.wParam)); }
int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE _hPrevInstance, LPSTR _lpCmdline, int _iCmdshow) { MSG msg; ZeroMemory(&msg, sizeof(MSG)); const int kiWidth = 400; const int kiHeight = 400; HWND hwnd = CreateAndRegisterWindow(_hInstance, kiWidth, kiHeight, L"My first sprite Game"); CGame& rGame = CGame::GetInstance(); if (!rGame.Initialise(_hInstance, hwnd, kiWidth, kiHeight)) { // Failed return (0); } while (msg.message != WM_QUIT) { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { rGame.ExecuteOneFrame(); } } CGame::DestroyInstance(); return (static_cast<int>(msg.wParam)); }