如何使用CreateWindowEx为窗口设置自定义颜色 [英] How to set custom color for window using CreateWindowEx

查看:974
本文介绍了如何使用CreateWindowEx为窗口设置自定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这样的窗口。我需要设置窗口的红色,例如:



 WNDCLASSEX MyClassStruct; 
const char MyClassName [] = MyClass;
MyClassStruct.style = CS_HREDRAW | CS_VREDRAW;
MyClassStruct.cbSize = sizeof (WNDCLASSEX);
MyClassStruct.lpfnWndProc = MyWndProc;
MyClassStruct.cbClsExtra = 0 ;
MyClassStruct.cbWndExtra = 0 ;
MyClassStruct.hInstance = hInstance;
MyClassStruct.hIcon = NULL;
MyClassStruct.hCursor = LoadCursor(NULL,IDC_ARROW);
HBRUSH redbru = CreateSolidBrush(RGB( 255 0 0 ));
MyClassStruct.hbrBackground = redbru;
MyClassStruct.lpszMenuName = NULL;
MyClassStruct.lpszClassName = MyClassName;

RegisterClassEx(& MyClassStruct);


CtrlsWnd = CreateWindowEx(WS_EX_TOPMOST,MyClassName,TEXT( title),WS_VISIBLE, 0 0 200
100 ,NULL,NULL,hInstance,NULL);





但结果是新创建的窗口有标准颜色 - COLOR_WINDOW。

为什么没有设置红色背景?

解决方案

谢谢大家的帮助!我解决了这个问题。问题出在垃圾中,这是在窗口程序中写的。我清理并修理了它。它完美无缺。


您将 redbru 分配给 ButClassStruct .hbrBackground 当您将 MyClassStruct 传递给 CreateWindowEx 时。

I created the window something like this. And I need to set the red color of the window, for example:

WNDCLASSEX MyClassStruct;
const char MyClassName[] = "MyClass";
MyClassStruct.style = CS_HREDRAW | CS_VREDRAW;
MyClassStruct.cbSize = sizeof(WNDCLASSEX);
MyClassStruct.lpfnWndProc = MyWndProc;
MyClassStruct.cbClsExtra = 0;
MyClassStruct.cbWndExtra = 0;
MyClassStruct.hInstance = hInstance;
MyClassStruct.hIcon = NULL;
MyClassStruct.hCursor = LoadCursor(NULL, IDC_ARROW);
HBRUSH redbru = CreateSolidBrush(RGB(255,0,0));
MyClassStruct.hbrBackground=redbru;
MyClassStruct.lpszMenuName = NULL;
MyClassStruct.lpszClassName = MyClassName;

RegisterClassEx (&MyClassStruct);


CtrlsWnd = CreateWindowEx(WS_EX_TOPMOST,MyClassName,TEXT("title"),WS_VISIBLE,0,0,200,
100,NULL,NULL,hInstance,NULL);



But as a result the newly created window has standard color - COLOR_WINDOW.
Why does not red background set up?

解决方案

Thank you all for your help! I solved the problem. The problem was in the garbage, which was written in the window procedure. I cleaned and fixed it. And it works perfectly.


You are assigning redbru to ButClassStruct.hbrBackground while you are passing MyClassStruct to the CreateWindowEx call.


这篇关于如何使用CreateWindowEx为窗口设置自定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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