// //Internal message procedure called from Wrapper function above // LRESULT Window::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { Root *root = Root::getInstance(); RenderSystem * rs = RenderSystem::getInstance(); switch( msg ) { // WM_ACTIVATE is sent when the window is activated or deactivated. // We pause the game when the window is deactivated and unpause it // when it becomes active. case WM_ACTIVATE: if( LOWORD(wParam) == WA_INACTIVE ) { root->pauseApp(); } else { root->startApp(); } return 0; // WM_SIZE is sent when the user resizes the window. case WM_SIZE: // Save the new client area dimensions. mClientWidth = LOWORD(lParam); mClientHeight = HIWORD(lParam); if( rs->getDevice() ) { if( wParam == SIZE_MINIMIZED ) //if minimzed then pause the app { root->pauseApp(); mMinimized = true; mMaximized = false; } else if( wParam == SIZE_MAXIMIZED ) //if maximized then make sure app is running { root->startApp(); mMinimized = false; mMaximized = true; rs->OnResize(); //react to resize by reallocating back buffer } else if( wParam == SIZE_RESTORED ) //size is restored from minized state { // Restoring from minimized state? if( mMinimized ) { root->startApp(); mMinimized = false; rs->OnResize(); //react to resize by reallocating back buffer } // Restoring from maximized state? else if( mMaximized ) { root->startApp(); mMaximized = false; rs->OnResize(); //react to resize by reallocating back buffer } else if( mResizing ) { // If user is dragging the resize bars, we do not resize // the buffers here because as the user continuously // drags the resize bars, a stream of WM_SIZE messages are // sent to the window, and it would be pointless (and slow) // to resize for each WM_SIZE message received from dragging // the resize bars. So instead, we reset after the user is // done resizing the window and releases the resize bars, which // sends a WM_EXITSIZEMOVE message. } else // API call such as SetWindowPos or mSwapChain->SetFullscreenState. { rs->OnResize(); } } } return 0; // WM_ENTERSIZEMOVE is sent when the user grabs the resize bars. case WM_ENTERSIZEMOVE: root->pauseApp(); mResizing = true; return 0; // WM_EXITSIZEMOVE is sent when the user releases the resize bars. // Here we reset everything based on the new window dimensions. case WM_EXITSIZEMOVE: root->startApp(); mResizing = false; rs->OnResize(); return 0; case WM_KEYDOWN: //was ESC pressed? Then close the app if( wParam == VK_ESCAPE ) { ::DestroyWindow(hwnd); return 0; } break; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: SetCapture(hwnd); // Capture mouse movement and mouse button up events outside the application window break; case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: ReleaseCapture(); // Stop capturing mouse movement and mouse button up events outside the application window break; case WM_DESTROY: // In the case of a destroy message, then ::PostQuitMessage(0); return 0; } if( !root->MsgProc( hwnd, msg, wParam, lParam ) ) //send to frame listeners! return 0; return DefWindowProc(hwnd, msg, wParam, lParam); //if no listeners consumed the message, send to default }