如何设置窗口的背景颜色后我注册了? [英] How to set background color of window after I have registered it?

查看:121
本文介绍了如何设置窗口的背景颜色后我注册了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有使用对话框,我使用我自己的自定义类,我已经注册,然后使用CreateWindow调用创建它,我已预设背景颜色为红色,注册时:

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.

我试图在WM_PAINT中使用SetBkColor()调用,并尝试从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.

任何帮助?

推荐答案

=http://msdn.microsoft.com/en-us/library/dd145204%28VS.85%29.aspx>窗口背景来自:

From Window Background comes:

...系统绘制
窗口的背景,或者给窗口
机会,通过发送
WM_ERASEBKGND消息, b $ b应用程序调用BeginPaint。如果
应用程序不处理
消息,但将其传递给
DefWindowProc,则系统通过在后台刷中填充
模式来擦除
背景
由窗口的类指定.....


......应用程序可以处理
WM_ERASEBKGND消息,即使
类后台刷被定义为。
这是典型的应用程序,
使用户可以更改窗口
背景颜色或模式为
指定的窗口,而不影响
类中的其他窗口。在这种
的情况下,应用程序不得将消息传递给DefWindowProc。 .....

...The system paints the background for a window or gives the window the opportunity to do so by sending it a WM_ERASEBKGND message when the application calls BeginPaint. If an application does not process the message but passes it to DefWindowProc, the system erases the background by filling it with the pattern in the background brush specified by the window's class.....

...... An application can process the WM_ERASEBKGND message even though a class background brush is defined. This is typical in applications that enable the user to change the window background color or pattern for a specified window without affecting other windows in the class. In such cases, the application must not pass the message to DefWindowProc. .....

因此,使用WM_ERASEBKGND消息的wParam来获取DC并绘制背景。

So, use the WM_ERASEBKGND message's wParam to get the DC and paint the background.

这篇关于如何设置窗口的背景颜色后我注册了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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