问题描述
我不使用一个对话框,使用im我已经登记自己的自定义类,然后用CreateWindow的调用来创建它,我有preset的背景色为红色注册时:
I am not using a dialog, im using my own custom class which i have registered and then used the CreateWindow call to create it, i have preset the background color to red when registering:
WNDCLASSEX wc;
wc.hbrBackground = CreateSolidBrush(RGB(255, 0, 0));
但现在我想改变在运行时的背景颜色,例如通过点击一个按钮,将其更改为蓝色。
but now i want to change the background color at runtime, by e.g. clicking a button to change it to blue.
我曾尝试使用SetBkColor()调用在WM_PAINT,并试图从WM_CTLCOLORDLG消息返回一个刷子,他们没有工作。
I have tried to use SetBkColor() call in the WM_PAINT, and tried returning a brush from the WM_CTLCOLORDLG message, they don't work.
任何帮助吗?
推荐答案
窗口背景来了:
...本系统描绘为一个背景
窗口或赋予该窗口的
机会通过发送这样做它
WM_ERASEBKGND消息时,
应用程序调用BeginPaint的。如果
应用程序不处理
消息而将它传给
DefWindowProc函数,系统擦除
背景通过用填充它
在后台刷模式
由窗口的类指定.....搜索结果
......一个应用程序可以处理
WM_ERASEBKGND消息,即使一
类背景画笔定义。
这是典型的应用程序
使用户能够改变窗口
背景颜色或图案为一
指定的窗口不影响
其他窗口中的类。在这样的
情况下,应用程序不得通过
消息给DefWindowProc函数。 .....
所以,使用WM_ERASEBKGND消息的wParam参数,以获得DC和油漆的背景。
So, use the WM_ERASEBKGND message's wParam to get the DC and paint the background.
这篇关于如何设置窗口的背景颜色我已经注册后呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!