int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_BASECODE, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } /*-------------------------- NEW CODE ---------------------------------*/ // set up the directx manager if(!dx.initialize(&hWnd)) { return FALSE; } /*---------------------------------------------------------------------*/ hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BASECODE)); // Main message loop: while (!quit) { if(PeekMessage(&msg, NULL, 0, 0, 1)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } // NEW CODE - render the current scene each time through Stats::startFPS(); dx.renderScene(); Stats::endFPS(); Utility::debugUpdate(); dx.update(); Stats::update(); } return (int) msg.wParam; }
/******************************************************************* * Main Window Procedure - handles application events *******************************************************************/ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CHAR: switch (wParam) { case 't': { if (dx.texturesEnabled) dx.disableTextures(); else dx.enableTextures(); dx.texturesEnabled = !dx.texturesEnabled; } break; case 'q': { dx.swapTexture(); } break; break; } break; // Allow the user to press the escape key to end the application case WM_KEYDOWN: switch (wParam) { case VK_ESCAPE: PostQuitMessage(0); break; } break; // The user hit the close button, close the application case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_MOVE: case WM_SIZE: Utility::resize(); break; case WM_CHAR: DeveloperConsole::catchCharacter((wchar_t)wParam); break; case WM_KEYDOWN: // check which key is pressed InputManager::keyDown(KeyState(wParam, lParam)); switch(wParam) { case VK_F5: dx.toggleFullScreen(); break; case VK_F4: killProgram(); break; } break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: killProgram(); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/******************************************************************* * WinMain *******************************************************************/ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { RedirectIOToConsole(); // Set up the application window if (!InitWindow( hInstance, nCmdShow, hWnd)) return 0; //set up direct x manager if (!dx.initialize(&hWnd , &hInstance)) return 0; // showing cursor: //ShowCursor(TRUE); //hTimer.StartTimer(); // Main message loop hTimer.Reset(); MSG msg = {0}; while (WM_QUIT != msg.message) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) { TranslateMessage(&msg); DispatchMessage(&msg); } else { //hTimer. hTimer.UpdateTime(); dx.renderScene(&hTimer); } } return (int) msg.wParam; }