怎么样改变对话框上控件的背景色?

解决方案 »

  1.   

    http://www.vctop.com/View.Asp?ID=426&CateID=1
      

  2.   

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

    // TODO: Change any attributes of the DC here

    // TODO: Return a different brush if the default is not desired
    if ((pWnd->GetDlgCtrlID() == IDC_STATIC1)||(pWnd->GetDlgCtrlID() == IDC_STATIC2)
    ||(pWnd->GetDlgCtrlID() == IDC_STATIC3)||(pWnd->GetDlgCtrlID() == IDC_CHECK1))
            {
                    pDC->SetTextColor(RGB(255, 155, 0));
    // pDC->SetBkColor(bkcolor);
    //                pDC->SetBkMode(OPAQUE);
    pDC->SetBkMode(TRANSPARENT);
    return (HBRUSH) m_brush .GetSafeHandle ( );
            }
    return hbr;
    }
      

  3.   

    1.声名几把刷子 ( Brush )
    HBRUSH m_hRedBrush;
    HBRUSH m_hYellowBrush;2.在 OnInitDialog() 里初始化 Bursh
    //Create brush
    m_hYellowBrush = CreateSolidBrush(RGB(255, 255, 128));
    m_hRedBrush = CreateSolidBrush(RGB(255, 0, 0));3.发送 WM_CTLCOLOR 消息,改变控件的背景色
    HBRUSH CLearnDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here switch(nCtlColor)
    {
    case CTLCOLOR_STATIC:  //Static 控件
    pDC->SetBkColor(RGB(255, 255, 0));
    return m_hYellowBrush;
    case CTLCOLOR_EDIT:  //Edit 控件
    pDC->SetBkColor(RGB(255, 0, 0));
    return m_hRedBrush;
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
    }
      

  4.   

    CTLCOLOR_BTN   Button control 
    CTLCOLOR_DLG   Dialog box 
    CTLCOLOR_EDIT   Edit control 
    CTLCOLOR_LISTBOX   List-box control 
    CTLCOLOR_MSGBOX   Message box 
    CTLCOLOR_SCROLLBAR   Scroll-bar control 
    CTLCOLOR_STATIC   Static control