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.
Chris becke
source share