![]() ![]() You still have to supply the scale factor for the fonts in use. Versions of MFC since Visual Studio 2010 support MFC scaling, although nothing happens by default. Return getFontHeight(dc->GetSafeHdc(), pointSize) Return getFontHeightForDefaultDC(pointSize) LONG getFontHeight(CDC *dc, // can be NULL for default screen LONG lfHeight = (LONG)((pointSize * (double)pixPerInch) / 72.0) this function can be optimized by using a simple cache on the point size (worth it in some situations!)ĭouble pointSize) // returns font height for the appropriate screen Getting a font pixel height LONG getFontHeightForDefaultDC(double pointSize) // returns font height for the appropriate screen Return getFontPointSize(dc->GetSafeHdc(), pixelSize) Return getFontPointSizeForDefaultDC(pixelSize) Points = getFontPointSize(hdc, pixelSize) we don't know the point size, calculate it LONG pixPerInch = GetDeviceCaps(hDC, LOGPIXELSY) ĭouble points = (pixelSize * 72.0) / pixPerInch ĭouble getFontPointSizeForDefaultDC(DWORD pixelSize) // returns font height for the appropriate screen Static FONT_HEIGHT_CACHE fontHeightCache map used as a cache for various point sizes #define POINT_SIZE_CACHE std::map // pixel height -> point size #define FONT_HEIGHT_CACHE std::map // point size -> pizel height some simple caching to speed things up double getSystemScaleFactor() // returns 1.0 for no scaling Stepping from a working system wide scaling to per monitor scaling should be a lot easier than going from non-scaling to per-monitor scaling in one go. If you are thinking of doing per-monitor scaling, you might be well served by first doing system wide scaling, because it is simpler and will introduce you to most of the problems you will face, but in an easier to manage problem space than per-monitor scaling. For the purposes of this discussion we will only cover getting the system scale factor. You can find out more about this using the GetDpiForMonitor() function. The ability to calculate a scale factor per monitor only works on Windows 8.1 and Windows 10 onwards. You can calculate a scale factor for the whole system, or a scale factor per monitor – if you have monitors with different display facilities. From this the following table follows: DPI Non scaled monitors are deemed to be monitors that display at 96 DPI. Once you have an appropriate point size for your normal non-scaled (non high-DPI) display you can then just get the correct font height in pixels (based on the point size) and multiply by a scale factor to determine the correct column width for any columns in grids, or any graphics that need scaling. You need to think in terms of point sizes for text, like you would if you are printing a document. This approach isn’t going to work with high DPI displays. No so good for your customers over 40 though, most of them are wearing glasses, and so will you be when you get there (or contacts, you know what I mean). “Oh, 14 look looks OK, I’ll go with that”. Which from what I’ve seen is how a lot of people (most?) do it. This is typical if you’ve specified your text height in pixels. But at your normal scaling the text on your displays starts looking a bit small. This provides wonderful scope for editing photographs and providing great graphics. Such monitors might have nearly 4000 pixels horizontally and over 2000 pixels vertically. License Information How our licences work.Ī few years ago Microsoft introduced support for very high resolution monitors.Cookie Usage Policy We promise not to feed the Cookie Monster.Privacy Policy How we treat any data that you provide to us. ![]()
0 Comments
Leave a Reply. |