views:

1478

answers:

5

By Windows PC displays, I am not referring to Windows CE, or handhelds, etc.

Clarification
Some folks below mistakenly thought I was asking what the DPI (dots per inch) was on monitors. What I'm asking for is the value for LogPixelsX in the GetCaps API call :

LOGPIXELSX Number of pixels per logical inch along the screen width.

In the examples I've seen, it's set to 88, regardless of the screen DPI. Seems to be a Magic Number sort of constant.

In a related Question I'm using GetDeviceCaps to calculate current Screen Font DPI. The code samples I found all have:

Const LOGPIXELSX = 88

Is this universally the same for all monitors (even widescreen vs regular monitors)? And if not, how do I find it for the current display. (MSDN indicates that it's the same for all monitors on a particular computer.

In a system with multiple display monitors, this value is the same for all monitors.

A: 

The two standard DPI settings in Windows are 96 dpi (Normal size) and 120 dpi (Large size) I'm sure there's a Win32 call for getting at this setting, but I'm not sure where to direct you for it. MSDN may have your answer.

edit: I should clarify that by Windows I mean Windows XP

dustyburwell
+2  A: 

Windows will always have 96 DPI for the resolution, unless you change it in the display settings. On XP, you find it in the Advanced dialog under Display Properties->Settings; I don't know where it's found in other versions of Windows.

You are correct that GetDeviceCaps(LOGPIXELSX) will return the DPI, except for one little caveat. Starting with Vista, Windows might lie to you about your actual configured resolution. You need to make your application DPI-aware to get a true picture of the configuration. Here's a Microsoft page providing some details, with special emphasis on changes coming in Windows 7.

http://msdn.microsoft.com/en-us/library/dd464659(VS.85).aspx

And another link:

http://msdn.microsoft.com/en-us/library/ms701681(VS.85).aspx

Mark Ransom
The 88 is the value of LOGPIXELSX, which is the value you pass to GetDeviceCaps() to get the logical pixels per inch on the X axis.
codekaizen
Thanks for clearing that up, I'll fix my answer.
Mark Ransom
A: 

See SetProcessDPIAware() (for Vista) and GetDeviceCaps(...) to get the DPI.

XP has 96 or 120 dpi. Vista actually has a slider to adjust through a "continuum" of DPI settings. On Vista, the DWM takes care of scaling your apps unless you explicitly call out that you are DPI-aware. For XP you should plan for both 96 and 120.

Nick
XP can set other dpi values too. You can definitely expect to see >120dpi on the monitors of the hard-of-seeing.
bobince
What about on mac's, becuase their displays always seem "crisper" than xp or vista?
CodeKiwi
Down voted for the incorrect info about XP ONLY having 2 modes (which is not correct as bobince pointed out).
Aardvark
+1  A: 

To answer your clarification of the question:

LOGPIXELSX is the parameter you pass to GetDeviceCaps to get the current monitor resolution (technically the horizontal resolution, but all modern displays have equal horizontal and vertical resolution). Yes, it is always 88 - if you wanted to get a different value from GetDeviceCaps, you'd pass in a different value. For example, to get the number of bits per pixel, you'd pass the BITSPIXEL constant which is 12. These magic constants are defined in the Windows API file WINGDI.h.

The note in MSDN is referring not to the parameter, but the returned value.

Mark Ransom
OK, I feel like an idiot now. It never occurred to me that it was a Constant determining *what* you were asking for. I thought it was *unit of measurement*. Thanks!
Clay Nichols
And I feel like an idiot for taking so long to figure out what you were asking for, so we're even.
Mark Ransom
A: 

For the case of image,image resolution(DPIX,DPIY) is to be taken other constant monitor resolution.twips to pixels convertion for image dpi is done as: public struct RECT_TAG { public int iLeft; public int iTop; public int iHeight; public int iWidth; } public static RECT_TAG ConvertTwipsToPixels(RECT_TAG pobjRect, int plXDPI, int plYDPI) { pobjRect.iLeft = pobjRect.iLeft * plXDPI / 1440; pobjRect.iTop = pobjRect.iTop * plYDPI / 1440; pobjRect.iWidth = pobjRect.iWidth * plXDPI / 1440; pobjRect.iHeight = pobjRect.iHeight * plYDPI / 1440; return pobjRect;

    }
Mohit Puri