vc Static背景 颜色

来源:互联网 发布:linux 文本文件忙 编辑:程序博客网 时间:2024/05/22 13:26

处理   WM_CTLCOLOR   消息

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

        if   (nCtlColor==CTLCOLOR_STATIC)      
        {
                pDC-> SetBkMode(TRANSPARENT);
                return   m_backHbrush;
        }
        return   hbr;
}
m_backHbrush定义为成员变量,HBRUSH类型,在OnInitDialog中初始化:
m_backHbrush=CreateSolidBrush(RGB(0,255,255));

 

void CXXXDlg::OnBnClickedBtnChange(){// get window handle of your static control CStatic* pStatic = (CStatic*)(GetDlgItem(IDC_STATIC_VARIETY));// init random generator srand(unsigned(time(NULL)));// release HBRUSH object last time ::DeleteObject(m_hbrMyBK);// create new brush and text color m_hbrMyBK= CreateSolidBrush(RGB(rand()% 256, rand()% 256, rand()% 256)); m_crlMyText= RGB(rand()% 256, rand()% 256, rand()% 256);// force to repaint your static control pStatic->Invalidate(TRUE);}HBRUSH CXXXDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor){ HBRUSH hbr= CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// if your static control...if(pWnd->GetDlgCtrlID()== IDC_STATIC_VARIETY){ pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(m_crlMyText); hbr = m_hbrMyBK; }return hbr;}

原创粉丝点击