Which is why I can't pass what you suggested of "800, 600, 32" - as that's 3 parameters? What should I pass as my value for the first parameter?
Printable View
Which is why I can't pass what you suggested of "800, 600, 32" - as that's 3 parameters? What should I pass as my value for the first parameter?
You need to be able to read and comprehend source code in order to write your own.
ggCode:#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
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
Still black-screens.
I even fiddled with it a bit and made it just go Sleep and then ChangeDisplay(0, 0);
It sleeps for 20 seconds... And then black-screens.
If you ran the above program, unmodified, and your screen went black and stayed that way - then you have a buggy video driver or an invalid monitor INF file.
Make sure your video drivers are up-to-date and that you're system recognizes your monitor correctly
From the start menu, run "desk.cpl". Is "Display" correct? What is your monitor's make/model?
If you run that main(), what is the output?Code: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
cout << "Found settings: " << dm << endl;
return 0;
}//main
gg
There's nothing wrong with my drivers, I can play video games that are programmed in C++ full-screen all the time.
Display comes up fine in "desk.cpl" - my monitor's just my TV, but the same thing happens when I run it through my "NEC AccuSync LCD 72VM" monitor.
And when I run that code it comes out as "800x600x32-75"
Run desk.cpl and change your settings to 800x600x32 via GUI. What happens?
gg
It changes to make itself 800x600.
What frequency does it use?
gg
60Hz I think. Although I can change it to 70 or 75Hz at 800x600 and it still runs fine.
In desk.cpl, is the display you are using labeled #1?
gg
Yes.
All I can say is get the latest drivers and try the code in post #17 again.
gg
If you run the program in post 17, what is the value of dm.dmFields after FindBestDisplayMode()?
It has a value of...
8126592
Seems like the DM_DISPLAYFLAGS flag is set. Maybe windows tries to change to an interlaced mode and your monitor can't handle that.
Try inserting
just before the first call to ChangeDisplaySettings()Code:dm.dmFields ^= DM_DISPLAYFLAGS;
dm.dmDisplayFlags = 0;
Btw, have you tried setting dm.dmDisplayFrequency to 0 to let windows auto select the refresh rate?