Vc如何改变对话框中控件文字的颜色和背景色

Vc未提供控件文字的颜色和背景色的函数,可以在ClassWizard中映射MW_CTRCOLOR消息,并在其消息处理函数OnCtlColor中加入如下代码:

HBRUSH CMyDialog::OnCtlColor(CDC* pDC,CWnd* pWnd,UINT nCtlColor)
{
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    
    // TODO:Change any attributes of the DC here
    m_brush.DeleteObject();
    m_brush.CreateSolidBrush(::GetSysColor(COLOR_3DFACE));
    
    if (pWnd->GetDlgCtrlID()<=IDC_AXIS8&&pWnd->GetDlgCtrlID()>=IDC_AXIS0
    ||pWnd->GetDlgCtrlID()>=IDC_AXISY5&&pWnd->GetDlgCtrlID()<=IDC_AXISY0)
    {
        hbr = (HBRUSH)( m_brush.GetSafeHandle()); // Passing a Handle to the Brush

        pDC->SetBkColor(::GetSysColor(COLOR_3DFACE));
        // Setting the Color of the Text Background to the one passed by the Dialog

    SetTextColor(pDC->GetSafeHdc(),m_pColorSetting->GetColorAxis());
        // Setting the Text Color to the one Passed by the Dialog
    }
    
    // Return a different brush if the default is not desired
    return hbr;
}


[本日志由 cnfgg 于 2009-08-24 03:40 PM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: vc 对话框 界面 消息映射 mfc
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.