Note that there are some explanatory texts on larger screens.

plurals
  1. POWin32 STATIC font wrong when grayed out
    text
    copied!<p>I am working on a Win32 program and want to enable and disable my controls. I am using the Windows XP theme and font. When I disable a STATIC control, the used font appears to be wrong. </p> <p>Enabled controls:<br> <img src="https://i.stack.imgur.com/U5FEm.jpg" alt="Correct font"><br> Disabled controls:<br> <img src="https://i.stack.imgur.com/A40dq.jpg" alt="Wrong font"></p> <p>In this image it is obvious what I mean:<br> <img src="https://i.stack.imgur.com/8yBhJ.png" alt="font detail"></p> <p>This code creates the font (I found it using Google):</p> <pre><code>HFONT CreateControlFont( void ) { // Get the system message box font NONCLIENTMETRICS ncm; ncm.cbSize = sizeof(ncm); // If we're compiling with the Vista SDK or later, the NONCLIENTMETRICS struct // will be the wrong size for previous versions, so we need to adjust it. // In versions of Windows prior to Vista, the iPaddedBorderWidth member // is not present, so we need to subtract its size from cbSize. #if( WINVER &lt; 0x0600 ) ncm.cbSize -= sizeof(ncm.iPaddedBorderWidth); #endif SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &amp;ncm, 0); return CreateFontIndirect(&amp;(ncm.lfMessageFont)); } </code></pre> <p>I apply it to my controls using <code>SendMessage(MY_WINDOW_HANDLE, WM_SETFONT, (WPARAM)MY_FONT, MAKELPARAM(FALSE, 0));</code>.</p> <p>I use this code to apply the XP style (also from the internet):</p> <pre><code>#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' \ version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \ language='*'\"") </code></pre> <p>This is how I create the STATIC controls:</p> <pre><code>HWND CreateLabel( const TCHAR * text, int x, int y, int w, int h, HMENU id, HWND parent ) { return CreateWindow( "static", text, WS_CHILD | WS_VISIBLE, x, y, w, h, parent, id, hInstance, NULL); } </code></pre> <p>To disable the controls I use <code>EnableWindow(MY_WND_HANDLE, FALSE);</code>.</p> <p>Now as you can see, this works as expected, except for when the control is grayed out. What am I doing wrong?</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