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

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

问题描述

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

I am not using a dialog, I'm 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.

有什么帮助吗?

推荐答案

来自 窗口背景来了:

...系统绘制背景窗口或给窗口有机会通过向其发送WM_ERASEBKGND 消息时应用程序调用 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天全站免登陆