简体   繁体   中英

Background color of CStatic issue

I'm having an issue with setting the background color of a CStatic using WTL (I'm guessing I'd have the same issue with MFC)

I have a window with a black background, that has a control that derives from CStatic on it. I'm setting the colors via the WM_CTLCOLORSTATIC message. I basically works, but the part of the control which does have text appears white.

Here is the code in the callback:

LRESULT CReportResults::OnCtrColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    if ((HWND)lParam == m_wndLoadingLabel.m_hWnd)
    {
        HDC     hDC = (HDC)wParam;

        SetBkColor(hDC, APP_COLOR_BACKGROUND);
        SetTextColor(hDC, APP_COLOR_TEXT);
    }
    return 0;
}

And here is what it ends up looking like on the screen. The control itself is larger than the text in it, but I'm not sure how to get the rest of the control to draw with a black background. It appears that setting the background color to black only effects the area where the text is displayed. Any ideas on what I might be doing incorrectly?

这就是它的样子

Found my mistake. I was returning zero in the OnCtrColorStatic handler. I switched to returning a brush which is used for the applications background color and everything works well now.

LRESULT CReportResults::OnCtrColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    if ((HWND)lParam == m_wndLoadingLabel.m_hWnd)
    {
        HDC     hDC = (HDC)wParam;

        SetBkColor(hDC, APP_COLOR_BACKGROUND);
        SetTextColor(hDC, APP_COLOR_TEXT);
    }
    return (LRESULT)g_app.background_brush;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM