I'm not sure I understand your problem. Your code looks pretty good. It should be noted that you are responsible for cleaning up the resources that you allocate. Using the code above, you are HBRUSH object created by calling CreateSolidBrush . Since you do not need a special brush, it is better to use GetSysColorBrush .
As a taste, I would filter out the control identifier, not its window handle, using GetDlgCtrlID . Including the changes, your code should look like this:
case WM_CTLCOLORSTATIC: switch ( GetDlgCtrlID( (HWND)lParam ) ) { case IDC_PID: //sets bckcolor of static text same as window color SetBkColor( (HDC)wParam, COLORREF( GetSysColor( COLOR_3DFACE ) ) ); SetTextColor( (HDC)wParam, RGB( 250, 50, 200) ); return (INT_PTR)GetSysColorBrush( COLOR_3DFACE ); default: // Message wasn't handled -> pass it on to the default handler return 0; }
source share