Screen Pixels per Inch

Screen pixels per inch (ppi) is the ratio of the number screen pixels to physical screen dimensions. Well, that’s simple enough except for the fact that while we know the number of screen pixels from the maximum video resolution (e.g. 1024 × 768) the only place Windows can get physical screen dimensions is from the monitor driver, and will attempt to do so via the Application Programming Interface (API).

The API is a massive library of programming functions that do all the grunt work. The relevant function is GetDeviceCaps (Get Device Capabilities) and, if it doesn’t send you to sleep, you can read the function description here for GetDeviceCaps. If you peruse this you will see the parameters for the function and the information one can retrieve. Two of those parameters are HORZSIZE and VERTSIZE

  • HORZSIZE = Width in millimeters of the physical screen
  • VERTSIZE = Height in millimeters of the physical screen

For my monitors, at maximum video resolution, I get:

Monitor HORZSIZE Measured Measured Pixels per Inch
Mitsubishi 19" CRT325 mm370 mm70.3
Toshiba Laptop270 mm285 mm91.26
ViewSonic 19" LCD380 mm376 mm86.47
Dell 19" LCD375 mm376 mm86.47

The screen width values that Windows has retrieved for the LCD screens are near enough to those obtained by measuring screens with a ruler, but are way out for the CRT and Laptop screens. You can see there’s a problem. A programmer can’t rely on Windows to get actual screen dimensions, and if you don’t know the real physical size of the screen then you can’t draw physical lengths on the screen that match those on a ruler. Screen Inches are not physical inches.

So what use is it to retrieve inaccurate screen dimensional information? Well, quite a lot actually because a programmer can use these dimensions to lay out things on screen. The fact that they are not accurate values is irrelevant, but that’s another topic completely.