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

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

问题描述

我不使用一个对话框,使用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函数。 .....

...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天全站免登陆