Changing the Screen's Display Settings

Although is it quite uncommon for an application to change the display settings of the end-user's monitor, certain types of applications may require this functionality.  Keep in mind that some changes will require a system reboot, while other settings are simply unsupported.  It is the job of the application to handle these situations.  Below, is an example of changing to 800x600; switching to other resolutions requires only changing the dmPelsWidth and dmPelsHeight members...
 

KEYWORDS: ChangeDisplaySettings(), EnumDisplaySettings(), DEVMODE. 
 



 

//---------------------------------------------------------------------------

void __fastcall TForm1::ChangeButtonClick(TObject *Sender)
{
    DEVMODE dm;
    dm.dmSize = sizeof(DEVMODE);

    int index = 0;
    while (EnumDisplaySettings(NULL, index, &dm))
    {
        if (dm.dmPelsWidth == 800 && dm.dmPelsHeight == 600)
        {
            dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
            LONG result = ChangeDisplaySettings(&dm, CDS_TEST);
            if (result == DISP_CHANGE_SUCCESSFUL)
            {
                ChangeDisplaySettings(&dm, 0);
                break;
            }
            else if (result == DISP_CHANGE_RESTART)
            {
                ShowMessage("Requires a reboot!");
                break;
            }
            else
            {
                ShowMessage("Setting unsupported.");
                break;
            }
        }
        index++;
    }
}