简体   繁体   English

如何创建具有透明背景的 window?

[英]How to create a window with transparent background?

Is possible/how to create a window without background or set her background transparent?是否可能/如何创建没有背景的 window 或将她的背景设置为透明?

Another way than using a layered window , because controls will be loaded into the window.使用分层 window 的另一种方法,因为控件将加载到 window 中。

My goal is to create a GUI with rounded borders, for that, I will load a picture as the background.我的目标是创建一个带有圆形边框的 GUI,为此,我将加载一张图片作为背景。

A layered window with the LWA_COLORKEY attribute is problematic if you want (Windows standard) child controls because there is no perfect color to pick as the transparent color.如果您想要(Windows 标准)子控件,则具有 LWA_COLORKEY 属性的分层 window 是有问题的,因为没有完美的颜色可供选择作为透明颜色。

However, layered windows have another mode;但是,分层 windows 有另一种模式; UpdateLayeredWindow . 更新分层窗口 This function is perfect if you have an image (with alpha transparency) you want to use as the background.如果您有一张想要用作背景的图像(具有 alpha 透明度),那么这个 function 是完美的选择。 Just make sure the bitmap is pre-multiplied 32-bit ARGB before selecting it into the DC.只需确保 bitmap 在将其选择到 DC 之前预乘 32 位 ARGB。

If for some crazy reason you can't use layered windows, the older option is SetWindowRgn .如果由于某些疯狂的原因您不能使用分层 windows,则较旧的选项是SetWindowRgn

The newer option is DirectComposition but I'm not sure if you are forced to set the layered style on the window.较新的选项是DirectComposition ,但我不确定您是否被迫在 window 上设置分层样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM