Programming Tips & Tricks

Home Categories: C# | C++ | General | Other

C++ Tips & Tricks: Setting Fullscreen Mode in Windows

The following code changes screen resolution and sets windows that are created as WS_POPUP into fullscreen mode:
bool EnterFullscreen ()
{
DEVMODE newSettings;
// now fill the DEVMODE with standard settings, mainly monitor frequenzy
EnumDisplaySettings ( NULL, 0, &newSettings );
// set desired screen size and resolution
newSettings.dmPelsWidth  = 800;
newSettings.dmPelsHeight = 600;
newSettings.dmBitsPerPel = 16;
//set those flags to let the next function know what we want to change
newSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
// and apply the new settings
if ( ChangeDisplaySettings ( &newSettings, CDS_FULLSCREEN ) 
!= DISP_CHANGE_SUCCESSFUL )
return false// in case of error
else return true;
}

And to reset the resolution:
void ResetScreen ()
{
// this resets the screen to the registry-stored values
   ChangeDisplaySettings ( NULL, 0 );
}