How can you tell (programmatically) if large fonts are in use on a Windows 7 PC
I need to identify whether or not large fonts are in use on Windows 开发者_StackOverflow7 from within an app written in C++. Any assistance would be appreciated.
In MFC:
void CTestFontDlg::OnBnClickedButton1()
{
CDC* pDC = GetDC();
int nRes = GetDeviceCaps(*pDC, LOGPIXELSY);
}
Normal font size = 96 (100%), medium (125%)= 120...
The Windows display settings (Control Panel\Appearance and Personalization\Display) affect the current number of dots per inch (DPI). There is in fact a way to get DPI information according to MSDN using GetDeviceCaps()
:
HDC hdc = ::GetDC(NULL);
int dpiX = ::GetDeviceCaps(hdc, LOGPIXELSX);
int dpiY = ::GetDeviceCaps(hdc, LOGPIXELSY);
::ReleaseDC(NULL, hdc);
This will give you the DPI in pixels. If you want the actual scale factor (g.e. 150%), divide by 96. 96 is the baseline DPI, so it's considered to be "100%". You can use MulDiv() so the integer division properly rounds the result if needed.
int scaleFactorX = ::MulDiv(dpiX, 100, 96);
int scaleFactorY = ::MulDiv(dpiY, 100, 96);
精彩评论