Change the Foreground and Background Colour of Staic Text Control in VC++

overrider OnCtlColor for WM_CTLCOLOR for your dialog like following to set background and text color :

e.g.

HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
     
      if(pWnd->m_hWnd== GetDlgItem(IDC_TEXT)->m_hWnd)  //Use static ID of your static text control
        {
        pDC->SetBkColor( RGB( 255, 0, 0 ) );  //red background
        pDC->SetTextColor( RGB( 255, 255, 255 ) );  //white text
        return hbr;
       }

     return hbr;
}

Otherwise derive your own control....like following
http://www.codeproject.com/staticctrl/coloredit_colorstatic.asp

posted on 2006-10-18 23:09  cy163  阅读(367)  评论(0编辑  收藏  举报

导航