c ++ win32:如何设置窗口的颜色? [英] c++ win32: how to set back color of a window?

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

问题描述

我可以在注册类时设置背景颜色,例如:

I can set the back color when i am registering the class, e.g.:

wincl.hbrBackground = CreateSolidBrush(RGB(202, 238, 255));
RegisterClassEx(&wincl);

但是我该如何做到使用CreateWindow函数创建的任何窗口?
像我的主窗口上的按钮,我有视觉样式启用,我可以注意到在按钮后面的窗口默认灰色背景颜色。

But how would i do it to any window i have created with the CreateWindow function? like a button on my main window, i have visual styles enabled, and i can notice the windows default gray back color behind the button.

不要告诉我我必须为窗口过程的SetWindowLong在allllllll我的控制和拦截WM_PAINT:(

Don't tell me i have to SetWindowLong for the window procedure on allllllll my controls and intercept the WM_PAINT :(

推荐答案

所有的窗口控件发送一个消息给他们的父母得到画笔用来填充他们的背景
假设你保存一个刷柄的副本某处,你可以在你的WindowProc或DialogProc中,以确保一切绘制与正确的背景画笔

All the windows controls send a message to their parent to get the brush to use to fill their background. Assuming you save a copy of the brush handle somewhere, you can do the following in your WindowProc, or DialogProc, to ensure everything draws with the correct background brush.

case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
  HDC hdc;
  HWND hwndCtl;
  POINT pt;
  hdc = (HDC)wParam;
  hwndCtl = (HWND)lParam;
  pt.x = 0;
  pt.y = 0;
  MapWindowPoints(hwndCtl,_hwnd,&pt,1);
  x = -pt.x;
  y = -pt.y;
  SetBrushOrgEx(hdc,x,y,NULL);
  return (INT_PTR)_skinBrush;

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

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