MFC 修改 STATIC控件颜色,字体颜色

1. 重写虚函数OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)

 

HBRUSH CTestToolDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    if (nCtlColor == CTLCOLOR_STATIC)
    {
        pDC->SetTextColor(RGB(rand() % 255, rand() % 255, rand() % 255));
       pDC->SetBkColor(RGB(rand() % 255, rand() % 255, rand() % 255));    }
    return hbr;
}

你可能感兴趣的:(MFC)