HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: Change any attributes of the DC here
if(nCtlColor == CTLCOLOR_EDIT)
{
if(pWnd->GetDlgCtrlID()==IDC_STATIC1))//设置控件IDC_STATIC1
{
pDC->SetBkColor(RGB(255,0,0));
return 一个刷子;
}
                  if(pWnd->GetDlgCtrlID()==IDC_STATIC2)//设置控件IDC_STATIC2
                  {
                           pDC->SetBkColor(RGB(0,255,0);
                           return 一个刷子;
                  }
}         if(nCtlColor==CTLCOLOR_EDIT)//设置对话框背景
         {
                 pDC->SetBkColor(...);
                 return 一个刷子
         }
// TODO: Return a different brush if the default is not desired
return hbr;
}

解决方案 »

  1.   

    怎么又有这样的问题?把下面的代码COPY过去,应该没问题的:HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here
    switch(pWnd->GetDlgCtrlID())
    {
    case IDC_STATIC1 : 
      pDC->SetTextColor(RGB(255,0,0));
      break;
    case IDC_STATIC2 :
      pDC->SetTextColor(RGB(0,255,0));
      break;
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;

      

  2.   

    为什么我会比 wistaria 晚了一步?
      

  3.   

    wistaria说得不错,当然如果你愿意也可以继承CStatic,然后重载它的OnPaint()
      

  4.   

    Thank all people!That's right!Add score!