views:

59

answers:

1

Is it possible to set the background color of a dialog button in Win32 without using an owner-drawn button?

The following paints the background of every dialog item except the buttons (not owner-drawn):

case WM_CTLCOLOREDIT:
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:

    HDC hdcStatic = (HDC)wParam;
    SetBkColor(hdcStatic, bgEditColor);    

    return (INT_PTR)bgBrushCurrent; // a red brush created earlier
+1  A: 

It is quite explicit in the SDK docs for the message:

Buttons with the BS_PUSHBUTTON, BS_DEFPUSHBUTTON, or BS_PUSHLIKE styles do not use the returned brush. Buttons with these styles are always drawn with the default system colors. Drawing push buttons requires several different brushes-face, highlight, and shadow-but the WM_CTLCOLORBTN message allows only one brush to be returned. To provide a custom appearance for push buttons, use an owner-drawn button.

Most Windows programs nowadays use the visual style selected by the user. Recommended, add the required manifest.

Hans Passant