Created
July 21, 2019 15:20
-
-
Save equalent/2cab86081f6514dbbde4338dd47dacb3 to your computer and use it in GitHub Desktop.
Fullscreen/Windowed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool GoFullscreen() | |
| { | |
| // turn off window region without redraw | |
| SetWindowRgn(m_hWindow, 0, false); | |
| DEVMODE newSettings; | |
| // request current screen settings | |
| EnumDisplaySettings(0, 0, &newSettings); | |
| // set desired screen size/res | |
| newSettings.dmPelsWidth = GetWidth(); | |
| newSettings.dmPelsHeight = GetHeight(); | |
| newSettings.dmBitsPerPel = 32; | |
| //specify which aspects of the screen settings we wish to change | |
| newSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; | |
| // attempt to apply the new settings | |
| long result = ChangeDisplaySettings(&newSettings, CDS_FULLSCREEN); | |
| // exit if failure, else set datamember to fullscreen and return true | |
| if ( result != DISP_CHANGE_SUCCESSFUL ) return false; | |
| else | |
| { | |
| // store the location of the window | |
| m_oldLoc = GetLocation(); | |
| // switch off the title bar | |
| DWORD dwstyle = GetWindowLong(m_hWindow, GWL_style); | |
| dwstyle &= ~WS_CAPTION; | |
| SetWindowLong(m_hWindow, GWL_style, dwstyle); | |
| // move the window to (0,0) | |
| SetWindowPos(m_hWindow, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER); | |
| InvalidateRect(m_hWindow, 0, true); | |
| return true; | |
| } | |
| } | |
| bool GoWindowedMode() | |
| { | |
| // this resets the screen to the registry-stored values | |
| ChangeDisplaySettings(0, 0); | |
| // replace the title bar | |
| DWORD dwstyle = GetWindowLong(m_hWindow, GWL_style); | |
| dwstyle = dwstyle | WS_CAPTION; | |
| SetWindowLong(m_hWindow, GWL_style, dwstyle); | |
| // move the window back to its old position | |
| SetWindowPos(m_hWindow, 0, m_oldLoc.x, m_oldLoc.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); | |
| InvalidateRect(m_hWindow, 0, true); | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment