1

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.

CarltonD
  • 23
  • 3
  • Define large. I know a dude who's fonts are like 2 times bigger than mine, and some people think that mine are big... –  Oct 11 '11 at 17:04
  • Windows Display Settings: Control Panel / Appearance / Display /...Smaller, Medium, Larger , where Larger = 150%. – CarltonD Oct 11 '11 at 17:08

2 Answers2

2

In MFC:

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

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

HappySDE
  • 36
  • 2
0

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);
In silico
  • 51,091
  • 10
  • 150
  • 143