Click here to Skip to main content
15,868,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I use WinXP SP3, Codeblocks w/MingW, SDL.

I'm wondering if anyone knows if it is possible to detect how wide a computer's screen is, such as #ifdef LAPTOP or something like that; I'm also aware of wider screens nowadays on some of the newer desktops. The reason is, I want my explosion to look round on all computers ideally. For my monitor I use "0.9 * the number that would be proper for x" to do things, but of course that would look like a sideways oval on wider screens like laptops or perhaps the newer monitors, though I've never used one of those yet so I could be wrong. Thanks for any and all replies! -B :)

edit 3-1-11: changed 0.8 to 0.9 above.
Posted
Updated 1-Mar-11 5:16am
v3

You can't use a #ifdef - that affects the code at compilation, where you need to affect it at run time.
Use GetSystemMetrics[^] - it gives all the info you will need.
 
Share this answer
 
Almost all displays these days have square pixels. That is, if there are, say 42 pixels in one vertical cm, there will be 42 in one horizontal cm. So circles and squares look right if drawn naturally (width-in-pixels = height-in-pixels).
Of course, the answers above are correct for finding the overall size of the display. Warning! Beware of multi-monitor setups. You need to be careful to distinguish between the size of any particular monitor and the size of the desktop. Finding out which one you are dealing with is not alsways easy.

Good luck!
 
Share this answer
 
v2
Comments
Henry Minute 26-Feb-11 11:53am    
From the OP - moved here from an answer.

thanks peter_in_2780, I know someone who has a muti-monitor setup, and that's good to know about the square pixels!

I have 5'd you on his behalf, since he seems to have forgotten to do so. :)
Use this code:

C++
DEVMODE dm;
ZeroMemory(&dm, sizeof(DEVMODE));
dm.dmSize = sizeof(DEVMODE);
if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
{
   // Width and height (in pixel) of the monitor are:
   int width = dm.dmPelsWidth;
   int height = dm.dmPelsHeight;
}
 
Share this answer
 
Thanks for the quick replies, I'll try both! and soon!
 
Share this answer
 
Another thing to consider is, if I set a full screen mode at 640x480, what will happen with a modern (wide) monitor; that would result in the pixels NOT being 1x1...so I guess I would have the user just have two choices on a screen-modification option screen, to have fullscreen 640x480 or a graphics mode with 480 lines and whatever number of columns to cause either a square pixel or a 1 to 0.9 ratio like my own. Then ask "Does this look right?" and have a button for yes or no. Thus the multi-monitor issue can be sidestepped.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900