How to set font and color for group header using Win32

I am stuck in WIN32 (no .NET or nothing failed)

+2
winapi
source share
3 answers

WM_CTLCOLORSTATIC is the correct way to control the color of the group header.

However, it no longer works: if your application uses the manifest to enable the comctl version 6 library, the Groupbox control no longer sends WM_CTLCOLORSTATIC to its parent to get the brush. If your dialog controls look ugly, square and gray - like Windows 95 controls, then you don't have xp styles and you can control the color of group boxes. But this is a terrible sacrifice !: P

Then, most standard controls send WM_CTLCOLORxxx messages WM_CTLCOLORxxx their parents (dialog box) to control their painting. The only way to identify controls is to search for their control identifiers, so assigning controls means an identifier that indicates that the control needs a specific color or font. those. do not use IDC_STATIC for controls that need red text. Set them to IDC_DRAWRED or to some id made.

Do not use GetDlgItem(hwndDlg,IDC_ID) == hwndCtl to check if there is a WM_CTLCOLOR message for proper control: GetDlgItem will simply return the handle of the first control in the dialog with a specific identifier, which means that only one control will be painted.

 case WM_CTLCOLORSTATIC: if(GetWindowLong( (HWND)lParam, GWL_ID) == IDC_RED) return MakeControlRed( (HDC)wParam ); 

You should always * return HBRUSH from the WM_CTLCOLORxxx message - even if you really just want to β€œinterfere” with the transmitted HDC. If you do not return the actual brush from your proc dialog, then the procedure dialog box will think that you did not process the message at all and passed it to DefWindowProc, which will reset any changes to the HDC. Instead of creating brushes, the system has a standby brush cache for drawing standard ui elements: GetSysColorBrush

Of course, you do NOT always need to return HBRUSH. If you have an xp theme style enabled in your application, you are sometimes allowed to return null: - since xp theme dialogs have different colored backgrounds (especially in tab controls), returning the syscolor brush will result in ugly gray boxes on a lighter background : - in these specific cases, the dialog manager will allow you to return null and NOT reset your changes to DC.

+3
source share

I think the WM_CTLCOLORSTATIC notification may be what you are after.

+1
source share

Well, you installed the font using the usual way to configure control fonts. Send the WM_SETFONT message to the window initialization using the HFONT created using CreateFont. eg.

  SendDlgItemMessage (hDlg, IDC_STATIC, WM_SETFONT, (WPARAM) hFont, TRUE); 

Then, as indicated, you need to use the WM_CTLCOLORSTATIC notification to set the actual color.

 case WM_CTLCOLORSTATIC:
 if (GetDlgItem (hDlg, IDC_STATIC) == (HWND) lParam)
 {
     HDC hDC = (HDC) wParam; 
SetBkColor (hDC, GetSysColor (COLOR_BTNFACE)); SetTextColor (hDC, RGB (0, 0xFF, 0)); SetBkMode (hDC, TRANSPARENT);
return (INT_PTR) CreateSolidBrush (GetSysColor (COLOR_BTNFACE));
} break;

Although you really only have to create a solid brush and remove it when the dialogue disappears, because you will end the leak.

0
source share

All Articles