如何在Win32中对组合框控件进行颜色处理? [英] How to colour group box controls in Win32?

查看:292
本文介绍了如何在Win32中对组合框控件进行颜色处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使文本的颜色和背景的组框控件。我正在使用对话框和Win32。为了说明我的问题,我创建了一个具有重现问题所需的最小代码的项目。

I am attempting to make the text colour and background of a group box control. I am using dialogs and Win32. To illustrate my problem I have created a project with the minimum code necessary to reproduce the issue.

如果我们采取一个对话框并将某种位图作为背景,可以很容易地看到组框控件的真实颜色。默认情况下,没有任何重写,它将如下所示:

If we take a dialog and put some sort of bitmap as the background, we can easily see the true colours of the group box control. By default without any overriding it will look like so:

我将尝试将文本颜色设置为白色,将文本背景设置为透明使用以下代码:

I will attempt to set the text colour to white and the text background to transparent with the following code:

case WM_CTLCOLORSTATIC: {
  HDC hDC = ( HDC )wParam;
  SetTextColor( hDC, RGB( 255, 255, 255 ) );
  SetBkMode( hDC, TRANSPARENT );
  return ( INT_PTR )GetStockObject( HOLLOW_BRUSH );
}

通过更改清单,我可以使用和不使用视觉样式来测试外观:

I tested the look with and without visual styling enabled by changing the manifest with:

#pragma comment(linker,"\"/manifestdependency:type='win32' \
    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
    processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

使用视觉样式,对话框如下所示:

With visual styles, the dialog looks like so:

背景更改为不可接受的纯色,取决于对话框的背景。文本颜色也无法更改。禁用视觉设计,对话框如下所示:

The background is changed to an unacceptable solid colour dependent on what the background of the dialog is. Also the text colour has failed to change. With visual styling disabled, the dialog looks like so:

文本颜色已更改,透明度已起作用,但组中的矩形我们已经上传了一个项目

The text colour has changed and the transparency has worked but the rectangle of the group box shows even where the text is.

=nofollow noreferrer>这里对任何有兴趣用它进行测试的人。

I have uploaded the project here for anyone interested in testing with it.

我已经在这个网站上看过其他类似的问题,是不可能没有子类或所有者抽签。我不介意子类化,但检查是否有更好的方法首先做。如果唯一的方法是子类化,那么对于什么应该被覆盖的信息(可能是WM_PAINT),我会很高兴。我已经在线上发现了人们创建自己的组框控件的示例,但有些似乎受到z订单问题的困扰。因此,使用子类化,是否需要处理WM_NCHITTEST?

I've read other similar questions on this site which seem to suggest perhaps this is not possible without subclassing or ownerdrawing. I don't mind subclassing but am checking there are not better ways to do it first. If the only way is subclassing, I would be happy for information on what should be overridden (probably WM_PAINT). I've found examples online of people creating their own group box controls but some seem to suffer from z-order issues. Therefore, with subclassing, would it be pertinent to handle WM_NCHITTEST?

同样,如果我用SetWindowLong()切换所有者绘制样式,然后将控件子类化以获取WM_DRAWITEM消息,有什么我应该注意的吗?如何处理视觉样式等?

Similarly, if I toggle the owner-draw style with SetWindowLong() and then subclass the control to get the WM_DRAWITEM messages, is there anything I should look out for? How should I deal with visual styles, etc.?

推荐答案

您是否尝试为WM_CTLCOLORSTATIC返回hBrBackground而不是GetStockObject(HOLLOW_BRUSH)?

Did you try returning hBrBackground instead of GetStockObject(HOLLOW_BRUSH) for WM_CTLCOLORSTATIC?

这篇关于如何在Win32中对组合框控件进行颜色处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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