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

原文地址:https://www.cnblogs.com/cy163/p/533041.html