Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Application initialization ---------------------------------------------------------
- bool Engine::CreateWindow(Int screenWidth, Int screenHeight, bool fullscreen)
- {
- WNDCLASSEX wc;
- DEVMODE dmScreenSettings;
- Int posX, posY;
- bool result;
- // Initialize the Windows API (and create a window)
- // Set display settings
- mScreenWidth = screenWidth;
- mScreenHeight = screenHeight;
- mFullscreen = fullscreen;
- // Get an external pointer to this object
- ApplicationHandle = this;
- // Get the instance of this application
- mHINSTANCE = GetModuleHandle(NULL);
- // Give the application a name
- mApplicationName = L"E-ngine";
- // Setup the windows class with default settings
- wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = mHINSTANCE;
- wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
- wc.hIconSm = wc.hIcon;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = mApplicationName;
- wc.cbSize = sizeof(WNDCLASSEX);
- // Register the window class
- RegisterClassEx(&wc);
- // Setup the screen settings depending on whether it is running in full screen or in windowed mode
- if(mFullscreen)
- {
- // If full screen set the screen to maximum size of the users desktop and 32bit
- mScreenWidth = GetSystemMetrics(SM_CXSCREEN);
- mScreenHeight = GetSystemMetrics(SM_CYSCREEN);
- //--//
- memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
- dmScreenSettings.dmSize = sizeof(dmScreenSettings);
- dmScreenSettings.dmPelsWidth = (uLong)mScreenWidth;
- dmScreenSettings.dmPelsHeight = (uLong)mScreenHeight;
- dmScreenSettings.dmBitsPerPel = 32;
- dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
- // Change the display settings to full screen
- ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
- // Set the position of the window to the top left corner
- posX = posY = 0;
- }
- else
- {
- // Place the window in the middle of the screen
- posX = (GetSystemMetrics(SM_CXSCREEN) - mScreenWidth) / 2;
- posY = (GetSystemMetrics(SM_CYSCREEN) - mScreenHeight) / 2;
- }
- // Create the window with the screen settings and get the handle to it
- mHWND = CreateWindowExW(WS_EX_APPWINDOW, mApplicationName, mApplicationName, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, posX, posY, mScreenWidth, mScreenHeight, NULL, NULL, mHINSTANCE, NULL);
- // Bring the window up on the screen and set it as main focus
- ShowWindow(mHWND, SW_SHOW);
- SetForegroundWindow(mHWND);
- SetFocus(mHWND);
- // Show/Hide the mouse cursor
- ShowCursor(true);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment