重载CDialog::OnCtlColor
使用参数pDC就可以了

解决方案 »

  1.   

    彩色按钮的源码例子:
    http://codeguru.earthweb.com/buttonctrl/color_button.shtml
      

  2.   

    响应 WM_CTLCOLOR 消息,下面的代码可以解决 Edit Box 和 Static:
    if(nCtlColor == CTLCOLOR_EDIT || nCtlColor == CTLCOLOR_BTN || nCtlColor == CTLCOLOR_STATIC)
    {
    pDC->SetBkColor(RGB(0, 128, 0));
    //pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(COLORREF(0xffffff));
    return m_br;
    }
    else 
    return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);CBrush m_br;
    在 OnInitDialog 中:
    m_br.CreateSolidBrush(RGB(0, 128, 0));按钮不太好办,下面是 msdn 上的说明:By default, the DefWindowProc function selects the default system colors for the button. 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.