Is the number of Pixels per Inch standard on all Windows PC displays? (LogPixelsX) in the GetDeviceCaps WinAPI call

StackOverflow https://stackoverflow.com/questions/645352

  •  22-07-2019
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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;

    }

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top