MFC - change text color of a cstatic text control

后端 未结 5 1095
野的像风
野的像风 2020-12-29 07:09

How do you change the text color of a CStatic text control? Is there a simple way other that using the CDC::SetTextColor?

thanks...

5条回答
  •  一生所求
    2020-12-29 07:55

    Just a follow up to the painting issue (a transparent background), which caused by *return (HBRUSH)GetStockObject(NULL_BRUSH);*

    Easy change as below:

    HBRUSH hBrush = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    
    if (nCtlColor == CTLCOLOR_STATIC &&
        pWnd->GetSafeHwnd() == GetDlgItem(XXX)->GetSafeHwnd()
    ) pDC->SetTextColor(RGB(255, 0, 0));    
    
    return hBrush;
    

    Hope this helps.

提交回复
热议问题