Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

EnumResolutions (Windows)

Sign in to follow this  


[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:

  • 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


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;
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;

Sign in to follow this  


Recommended Comments


Did you check if the duplicates reference the same device? Im suspecting that they don't. Just a hunch.

Actually no, I saw this in MSDN so:


[in] Pointer to a null-terminated string that specifies the display device about whose graphics mode the function will obtain information.
This parameter is either NULL or a DISPLAY_DEVICE.DeviceName returned from EnumDisplayDevices. A NULL value specifies the current display device on the computer on which the calling thread is running.

So I thought, NULL will give me the current display device which was exactly what I wanted. But then again, I didn't check if this was somehow incorrect because it would explain why I have multiple resolutions!


oh, btw, you do realize that you print:

Width Width BPP

as file header :p

Yes, it's a feature!

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!