I am trying to use ChangeDisplaySettings to change the default display device desktop resolution. However, when I execute my function ( set_resolution), ChangeDisplaySettings always succeeds despite the fact that I do not see any obvious changes in the desktop resolution (the return code is always DISP_CHANGE_SUCCESSFUL).
I tried every value for dwFlags, but for each value I get the same result. I tried several resolutions that my display should support, but I get the same result. My display is 16: 9, native 1920x1080. I tried, for example, 1280x720.
I tried to execute set_resolutionat the same time as creating the window, and also tried to execute a function in every event WM_ACTIVATE.
LONG set_resolution(uint32_t width, uint32_t height)
{
DEVMODE dm;
dm.dmPelsWidth = width;
dm.dmPelsHeight = height;
dm.dmBitsPerPel = 32;
dm.dmDisplayFrequency = 60;
dm.dmFields =
DM_PELSWIDTH |
DM_PELSHEIGHT |
DM_BITSPERPEL |
DM_DISPLAYFREQUENCY;
DWORD flags =
0;
LONG code = ChangeDisplaySettings(&dm, flags);
if (code == DISP_CHANGE_SUCCESSFUL)
{
printf("Display change successful [%dx%d]: %d", width, height, flags);
}
else
{
printf("Display change failed [%dx%d]: %d", width, height, code);
}
return code;
}
source
share