-
Code:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
bool FindBestDisplayMode(DEVMODE &best, DWORD width, DWORD height, DWORD bpp)
{
DEVMODE dm = {0};
dm.dmSize = sizeof(DEVMODE);
DWORD n, maxFreq = 0;
bool found = false;
for (n = 0; EnumDisplaySettings(NULL, n, &dm); n++)
{
if ((dm.dmPelsWidth == width) &&
(dm.dmPelsHeight == height) &&
(dm.dmBitsPerPel == bpp))
{
if ((dm.dmFields & DM_ORIENTATION) &&
(dm.dmOrientation != DMDO_DEFAULT))
{
// only select default orientation
continue;
}//if
if (dm.dmDisplayFrequency > maxFreq)
{
maxFreq = dm.dmDisplayFrequency;
best = dm;
found = true;
}//if
}//if
}//for
return found;
}//FindBestDisplayMode
ostream& operator<<(ostream &out, const DEVMODE &dm)
{
return out << dm.dmPelsWidth << 'x' << dm.dmPelsHeight << 'x'
<< dm.dmBitsPerPel << '-' << dm.dmDisplayFrequency;
}//ostream << DEVMODE
int main()
{
const DWORD W = 800, H = 600;
DEVMODE dm;
bool bFound = FindBestDisplayMode(dm, W, H, 32) ||
FindBestDisplayMode(dm, W, H, 16);
if (!bFound)
{
cerr << H << 'x' << W << " resolution not found." << endl;
return 1;
}//if
dm.dmFields ^= DM_DISPLAYFLAGS;
dm.dmDisplayFlags = 0;
dm.dmDisplayFrequency = 0;
LONG cds = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
if (cds != DISP_CHANGE_SUCCESSFUL)
{
cerr << "Failed to change display settings to "
<< dm << ", ec=" << GetLastError() << endl;
return 2;
}//if
cout << "Display now in " << dm << endl;
cout << "Enjoy for the next 20 seconds..." << endl;
Sleep(20 * 1000);
cds = ChangeDisplaySettings(0, 0);
if (cds != DISP_CHANGE_SUCCESSFUL)
{
cerr << "Uh-Oh, didn't change back, ec=" << GetLastError() << endl;
return 3;
}//if
return 0;
}//main
That's my code then, with the DisplayFlags thing and the DisplayFrequency... Same result :(