一劳永逸:如何在Windows API中获得完全透明的复选框,按钮,单选按钮等,而不是黑色背景? [英] Once and for all: how do I get a fully transparent checkbox, button, radio button, etc. in Windows API, and not with a black background?

查看:321
本文介绍了一劳永逸:如何在Windows API中获得完全透明的复选框,按钮,单选按钮等,而不是黑色背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,对不起,如果我在这里听起来很自大/粗鲁.

First, sorry if I sound arrogant/rude here.

好的,所以现在每个人都已经碰到了这一点(我希望);我只是在任何地方都没有找到任何适当的答案.我们从Common Controls 6清单开始,然后

All right, so everyone has run into this by now (I hope); I just haven't found any adequate answer anywhere. We start with a Common Controls 6 manifest and

case WM_CTLCOLORSTATIC:
    if (/* window has WS_EX_TRANSPARENT */) {
        SetBkMode((HDC) wParam, TRANSPARENT);
        return (LRESULT) GetStockObject(HOLLOW_BRUSH);
    }

,并给我们加上标签WS_EX_TRANSPARENT.它们变得透明;到目前为止,一切都很好.现在,我们必须将该样式添加到我们的复选框中(因为复选框会对此进行响应,而不是出于某些原因而不响应WM_CTLCOLORBTN).而且...复选框变成黑色!

and give our labels WS_EX_TRANSPARENT. They become transparent; so far so good. Now we have to add that style to our checkboxes (because checkboxes respond to that and not to WM_CTLCOLORBTN for some reason). And... the checkboxes become black!

有没有什么方法可以使它们完全透明而不诉诸所有者抽奖?我宁愿自己不要画复选框.我宁愿不必猜测主题API是否对我来说看起来正确还是大小合适(将来,当我在列表视图中添加自定义复选框时,我将不得不自己绘制复选框)并且我已经对涉及的猜测数量感到不满意了.

Is there any way to make them fully transparent without resorting to owner draw? I'd rather not draw the checkboxes myself; I'd rather not have to guess whether it looks right or what the sizes are should the theming API fail on me (and I'm going to have to draw check boxes by themselves in the future when I add custom checkboxes to my list views and I'm already not happy with the amount of guessing involved).

这些复选框是通过主题选项卡控件绘制的.到目前为止,我已经在Windows XP中找到了五个对话框,在主题选项卡上具有透明复选框:快捷方式属性的常规选项卡,任务栏和开始菜单属性的任务栏选项卡,系统属性的系统还原选项卡,文件夹选项的常规选项卡(单选按钮) ,以及辅助功能选项"的键盘"标签.因此,这肯定是有可能的!我确定Windows UI作者不必在整个OS上使用自定义绘图...我们都缺少什么?

These checkboxes are being drawn over a themed tab control. So far, I've found five dialogs in Windows XP with transparent checkboxes on themed tabs: General tab of Shortcut Properties, Taskbar tab of Taskbar and Start Menu Properties, System Restore tab of System Properties, General tab of Folder Options (radio buttons), and Keyboard tab of Accessibility Options. So this certainly must be possible! I'm sure the Windows UI authors didn't have to use custom draw throughout the OS... What are we all missing?

如果我需要很好的子类化(为了事件处理的目的,我已经有一个子类化了),但是我还是不想画自己.

If I need to subclass that's fine (I already have a subclass anyway for event handling purposes), but I still would rather not have to draw myself.

作为奖励,按钮呢?覆盖WM_CTLCOLORBTN会给按钮一个黑色边框,但是我确实注意到上面提到的所有标准对话框都没有使按钮的角变得透明,所以eh:/

As a bonus, what about push buttons? Overriding WM_CTLCOLORBTN gives buttons a black border, but I do notice that none of the standard dialogs mentioned above bother to make the corners of buttons transparent, so eh :/

谢谢!

推荐答案

您必须返回窗口注册类的hbrBackground元素,如下所示:

You have to return the hbrBackground element of registered class of window as follow:

case WM_CTLCOLORBTN:
case WM_CTLCOLORSTATIC: {
    wchar_t  class_Name[100];
    GetClassName(hWnd, class_Name, 100);
    WNDCLASS lpcls{};
    GetClassInfo(g_hInstance, class_Name, &lpcls);

    return  (LRESULT)lpcls.hbrBackground;
}

这篇关于一劳永逸:如何在Windows API中获得完全透明的复选框,按钮,单选按钮等,而不是黑色背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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