简体   繁体   English

CStatic问题的背景颜色

[英]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) 我在使用WTL设置CStatic的背景颜色时遇到问题(我猜我的MFC也有同样的问题)

I have a window with a black background, that has a control that derives from CStatic on it. 我有一个黑色背景的窗口,它有一个源自CStatic的控件。 I'm setting the colors via the WM_CTLCOLORSTATIC message. 我正在通过WM_CTLCOLORSTATIC消息设置颜色。 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. 我在OnCtrColorStatic处理程序中返回零。 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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