Win32下如何改变STATIC文本的颜色? [英] In Win32, how can the colour of STATIC text be changed?

查看:27
本文介绍了Win32下如何改变STATIC文本的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个黑色窗口上有一些静态文本,我想在运行时使用颜色选择器对话框更改它.我已经成功获取了颜色,现在我只需要更改文本即可!我已经读到 WM_CTLCOLORSTATIC 消息是要处理的消息,尽管这似乎只适用于最初将控件绘制到屏幕上的情况.可以使用 WM_PAINT 吗?

I have some static text on a window which is black, and I would like to change it at runtime using a Colour Chooser dialog. I have successfully obtained the colour, now I just need to change the text! I have read that the WM_CTLCOLORSTATIC message is the one to handle, although this appears to only be for when the control is initially drawn to the screen. Could WM_PAINT be used?

到目前为止,我设置颜色的代码是(在 WM_CTLCOLORSTATIC 情况下):

The code for setting the colour I have so far is (in WM_CTLCOLORSTATIC case):

if ((HWND)lParam == GetDlgItem(hWnd, uLabelId)
{
    SetBkMode((HDC)wParam, TRANSPARENT);
    SetTextColor((HDC)wParam, crLabelTextColour);
    return (BOOL)CreateSolidBrush(GetSysColor(COLOR_MENU));
}

我在处理这个问题时可能完全搞错了,所以任何帮助都将不胜感激!

I may have got entirely the wrong end of the stick approaching this issue, so any assistance would be greatly appreciated!

推荐答案

WM_CTLCOLORSTATIC 您走在正确的轨道上.如果要更改颜色,则使控件无效(可能通过使用 RedrawWindow).这将导致它被重新粉刷.重新绘制后,您的 WM_CTLCOLORSTATIC 处理程序将再次被调用.

You're on the right track with WM_CTLCOLORSTATIC. If you want to change the color, then invalidate the control (probably by using RedrawWindow). That will cause it to be repainted. When it's repainted, your WM_CTLCOLORSTATIC handler will be invoked again.

这篇关于Win32下如何改变STATIC文本的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆