如何使用不透明的子控件(或子窗口)创建透明窗口? [英] How to create a transparent window with non-transparent child controls (or child windows)?

查看:48
本文介绍了如何使用不透明的子控件(或子窗口)创建透明窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我正在使用 C++ 开发 Win32.

First, I'm working on Win32 with C++.

我一直在尝试实现一个带有子窗口的透明窗口,该窗口应该保持 100% 不透明.似乎子控件的不透明度不能比父控件更好(更低),如果我让我的父控件 100% 透明,那么我的子控件也会继承透明度.

I have been trying to implement a transparent window with a child window which should remain 100% opaque. It seems that child controls cannot have opacity better(lower) than the parent and if I make my parent 100% transparent then my child control also inherits the transparency.

我使用的代码 -

SetLayeredWindowAttributes(GetParent(parentWindowHwnd), 0, 0, LWA_COLORKEY, LWA_ALPHA); 

有什么帮助吗?

如果我对我的问题不是很清楚,也请回复.

Please also reply if I am not very clear with my question.

推荐答案

不幸的是,您不能这样做,子窗口始终具有与其父窗口相同的不透明度.Google 桌面工具栏有一个巧妙的技巧,可以在半透明背景上产生不透明文本框的错觉.他们创建了两个顶级窗口,一个是背景,一个是文本框.然后他们将背景窗口设置为 texbox 的所有者(而不是 parent).然后他们将背景设置为透明.要做到正确需要做很多工作,但这是唯一一种无需使用 UpdateLayeredWindow 自己渲染整个内容的方法.

You can't do this unfortunately, child windows always have the same opacity as their parent. The Google Desktop Toolbar had a neat trick to give the illusion of an opaque textbox on a translucent background. They created two top level windows, one of the background and one for the textbox. Then they set the background window as the owner (not the parent) of the texbox. They then set the background as transparent. It's quite a bit of work to get right, but it's the only way to do it without rendering the whole thing yourself using UpdateLayeredWindow.

这篇关于如何使用不透明的子控件(或子窗口)创建透明窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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