关于修改CEdit控件背景颜色总结

来源:互联网 发布:wifi网络卡怎么办 编辑:程序博客网 时间:2024/06/07 01:40

修改控件的背景颜色,需要添加消息

    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);ON_WM_CTLCOLOR()HBRUSH CPC21Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);    // TODO: Change any attributes of the DC here    int id =::GetDlgCtrlID(pWnd->m_hWnd);//取得ID    if(id == IDC_EDIT16)    {        COLORREF bkColor = 0xC6FD0A;             CRect rcRect;        pWnd->GetClientRect( &rcRect );        pDC->FillSolidRect(rcRect, bkColor);        pDC->SetBkColor(bkColor);    }    // TODO: Return a different brush if the default is not desired    return hbr;}

pDC->SetBkColor(bkColor)只能修改控件背景文字的颜色,不能将整个控件的背景设置为制定颜色。
pDC->FillSolidRect(rcRect, bkColor);实现将整个控件的背景颜色进行重绘
备注:获取系统颜色long color = GetSysColor(COLOR_WINDOW);

0 0
原创粉丝点击