How can you tell (programmatically) if large fonts are in use on a Windows 7 PC

久未见 提交于 2019-12-24 12:10:13

问题


I need to identify whether or not large fonts are in use on Windows 7 from within an app written in C++. Any assistance would be appreciated.


回答1:


In MFC:

void CTestFontDlg::OnBnClickedButton1()
{
    CDC* pDC = GetDC();
    int nRes = GetDeviceCaps(*pDC, LOGPIXELSY);
}

Normal font size = 96 (100%), medium (125%)= 120...




回答2:


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);


来源:https://stackoverflow.com/questions/7729725/how-can-you-tell-programmatically-if-large-fonts-are-in-use-on-a-windows-7-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!