Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't detect when Windows Font Size has changed C++ MFC
    text
    copied!<p>I'm trying to determine how I can detect when the user changes the Windows Font Size from Normal to Extra Large Fonts, the font size is selected by executing the following steps on a Windows XP machine:</p> <ol> <li>Right-click on the desktop and select Properties.</li> <li>Click on the Appearance Tab.</li> <li>Select the Font Size: Normal/Large Fonts/Extra Large Fonts</li> </ol> <p>My understanding is that the font size change results in a DPI change, so here is what I've tried so far.</p> <hr> <h2>My Goal:</h2> <p>I want to detect when the <strong>Windows Font Size</strong> has changed from Normal to Large or Extra Large Fonts and take some actions based on that font size change. I assume that when the Windows Font Size changes, the DPI will also change (especially when the size is Extra Large Fonts</p> <hr> <h2>What I've tried so far:</h2> <p>I receive several messages including: WM_SETTINGCHANGE, WM_NCCALCSIZE, WM_NCPAINT, etc... but none of these messages are unique to the situation when the font size changes, in other words, when I receive the WM_SETTINGSCHANGE message I want to know what changed.</p> <p>In theory when I define the OnSettingChange and Windows calls it, the lpszSection should tell me what the changing section is, and that works fine, but then I check the given section by calling SystemParametersInfo and I pass in the action SPI_GETNONCLIENTMETRICS, and I step through the debugger and I make sure that I watch the data in the returned NONCLIENTMETRICS for any font changes, but none occur.</p> <p>Even if that didn't work, I should still be able to check the DPI when the Settings change. I really wouldn't care about the other details, every time I get the WM_SETTINGCHANGE message, I would just check the DPI and perform the actions I'm interested in performing, but I'm not able to get the system DPI either.</p> <p>I have tried to get the DPI by invoking the method GetSystemMetrics, also for each DC:</p> <p>Dekstop DC->GetDeviceCaps LOGPIXELSX/LOGPIXELSY Window DC->GetDeviceCaps LOGPIXELSX/LOGPIXELSY Current DC->GetDeviceCaps LOGPIXELSX/LOGPIXELSY</p> <p>Even if I change the DPI in the Graphic Properties Window these values don't return anything different, they always show 96.</p> <p>Could anybody help me figure this out please? What should I be looking for? Where should I be looking at?</p> <pre><code>afx_msg void CMainFrame::OnSettingChange(UINT uFlags, LPCTSTR lpszSection) { int windowDPI = 0; int deviceDPI = 0; int systemDPI = 0; int desktopDPI = 0; int dpi_00_X = 0; int dpi_01_X = 0; int dpi_02_X = 0; int dpi_03_X = 0; CDC* windowDC = CWnd::GetWindowDC(); // try with window DC HDC desktop = ::GetDC(NULL); // try with desktop DC CDC* device = CWnd::GetDC(); // try with current DC HDC hDC = *device; // try with HDC if( windowDC ) { windowDPI = windowDC-&gt;GetDeviceCaps(LOGPIXELSY); // always 96 regardless if I change the Font // Size to Extra Large Fonts or keep it at Normal dpi_00_X = windowDC-&gt;GetDeviceCaps(LOGPIXELSX); // 96 } if( desktop ) { desktopDPI = ::GetDeviceCaps(desktop, LOGPIXELSY); // 96 dpi_01_X = ::GetDeviceCaps(desktop, LOGPIXELSX); // 96 } if( device ) { deviceDPI = device-&gt;GetDeviceCaps(LOGPIXELSY); // 96 dpi_02_X = device-&gt;GetDeviceCaps(LOGPIXELSX); // 96 } systemDPI = ::GetDeviceCaps(hDC, LOGPIXELSY); // 96 dpi_03_X = ::GetDeviceCaps(hDC, LOGPIXELSX); // 96 CWnd::ReleaseDC(device); CWnd::ReleaseDC(windowDC); ::ReleaseDC(NULL, desktop); ::ReleaseDC(NULL, hDC); CWnd::OnWinSettingChange(uFlags, lpszSection); } </code></pre> <p>The DPI always returns 96, but the settings changes DO take effect when I change the font size to Extra Large Fonts or if I change the DPI to 120 (from the graphics properties).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload