EnumResolutions (Windows)
778
4
Advertisement
[edit:] updated source 8/8-05
So friendly EDI from Etheral Darkness Interactive (a.k.a. Edi Did It) asked me if I could make an enumerator for resolutions, since on my little lappy I get repeated resolutions (like 4 "different" 800x600 where two is 16bpp and two is 32bpp) and we were both curious on why since repeated resolutions are filtered.
After playing around with CreateFile/WriteFile for an hour, I gave up and returned to good old std::ofstream for outputing the data. And after another hour I gave up on trying to find out why I have two 16bpp and two 32bpp - and no they don't have different refresh rates, the refresh rate and display flags are the same for those. This data wouldn't be used anyway...
So basicly, I had these requirements:
To solve the first requirement I used EnumDisplaySettings as EDI had suggested.
To solve the second requirement I used a std::set of resolution structs, providing my own compare by overloading operator <. Note: I chose not to make it a member so i could construct it using a initialization list. Saves number of keys I have to press to write the code and makes the struct a simple variable holder :P
Well I did it, might as well share =)
Sharing is love
So friendly EDI from Etheral Darkness Interactive (a.k.a. Edi Did It) asked me if I could make an enumerator for resolutions, since on my little lappy I get repeated resolutions (like 4 "different" 800x600 where two is 16bpp and two is 32bpp) and we were both curious on why since repeated resolutions are filtered.
After playing around with CreateFile/WriteFile for an hour, I gave up and returned to good old std::ofstream for outputing the data. And after another hour I gave up on trying to find out why I have two 16bpp and two 32bpp - and no they don't have different refresh rates, the refresh rate and display flags are the same for those. This data wouldn't be used anyway...
So basicly, I had these requirements:
- Find the resolutions, in the form: Width, Height, Bits per pixel.
- Sort them in a user expected way.
To solve the first requirement I used EnumDisplaySettings as EDI had suggested.
To solve the second requirement I used a std::set of resolution structs, providing my own compare by overloading operator <. Note: I chose not to make it a member so i could construct it using a initialization list. Saves number of keys I have to press to write the code and makes the struct a simple variable holder :P
Well I did it, might as well share =)
Sharing is love
#define VC_EXTRALEAN#include #include #include #include #include #include struct Resolution{ int width, height, bpp;};std::ostream& operator << ( std::ostream& out, const Resolution& res ){ const char tab = 'x'; out << res.width << tab << res.height << tab << res.bpp; return out;}bool operator < ( const Resolution& lhs, const Resolution& rhs ){ if( lhs.width < rhs.width ) return true; else if( lhs.width == rhs.width ) return lhs.bpp < rhs.bpp; return false;}typedef std::set ResolutionHolder;ResolutionHolder FindResolutions(){ DEVMODE devmode; devmode.dmSize = sizeof(DEVMODE); devmode.dmDriverExtra = 0; DWORD modeNum = 0; ResolutionHolder result; while( EnumDisplaySettings( NULL, modeNum++, &devmode ) != 0 ) { Resolution res = { devmode.dmPelsWidth, devmode.dmPelsHeight, devmode.dmBitsPerPel }; result.insert( res ); } return result;}int APIENTRY WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpCmdLine*/, int /*nCmdShow*/){ ResolutionHolder resolutions = FindResolutions(); /* Here you have 'resolutions' full of sorted resolutions! =D */ // output for your pleasure std::ofstream file("resolutions.txt"); const char* tab = " "; file << "Width" << tab << "Height" << tab << "BPP" << std::endl; std::copy( resolutions.begin(), resolutions.end(), std::ostream_iterator(file, "\n") ); return 0;}Advertisement
Advertisement
Advertisement
Discussion