Change resolution with ChangeDisplaySettings while desktop is extended caused black screen

Started by
-1 comments, last by Timi11 8 years, 9 months ago

Hi.

I use this function to change resolution:

ChangeResolution(NULL,1440, 900);

bool ChangeResolution(WCHAR *sDeviceName, int iNewW, int iNewH)
{
DEVMODE oDEVMODE = { 0 };
oDEVMODE.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(sDeviceName, ENUM_CURRENT_SETTINGS, &oDEVMODE);

oDEVMODE.dmPelsWidth = iNewW;
oDEVMODE.dmPelsHeight = iNewH;
bool bUpdateReg = true;
LONG lRet = ChangeDisplaySettings(&oDEVMODE, CDS_TEST | CDS_UPDATEREGISTRY);
if (lRet != DISP_CHANGE_SUCCESSFUL)
{
lRet = ChangeDisplaySettings(&oDEVMODE, CDS_TEST);
bUpdateReg = false;
}
if (lRet == DISP_CHANGE_SUCCESSFUL)
lRet = ChangeDisplaySettings(&oDEVMODE, bUpdateReg?CDS_UPDATEREGISTRY : 0);

return lRet == DISP_CHANGE_SUCCESSFUL;
}

This works well.

Problem happens when I desktop is extended (pressing the Windows key + P and choosing "extend"). Then while desktop is extended (to non psychical display), after using my ChangeResolution the screen become black as soon as my function calls ChangeDisplaySettings(&oDEVMODE, bUpdateReg?CDS_UPDATEREGISTRY : 0);

The way to get the screen back is to press Windows Key+P again and then press Enter.

(Since screen is black you do not really see what you do).

It becomes black no matter which new resolution i set.

If I try to change resolution while in extended mode but from Control Panel that is works great so the problem is with my function.

I think this happens since when i change resolution for the default screen (NULL), i also need to change something for the virtual screen - but i am not sure.

If that helps, seems that the screen goes black since for some reason after calling the changeresolution function, display1 is removed and display2 (the virtual screen) is on, but since there is not really physical display2 then i see black screen.

Question is why Display1 is removed when changing resolution?

Any help?

Thanks!

This topic is closed to new replies.

Advertisement