Win32:如何使投影荣誉非矩形“分层"窗口? [英] Win32: How to make drop shadow honor non-rectangular Layered window?
问题描述
我创建了分层窗口,方法是添加 WS_EX_LAYERED 扩展样式:
i've created a layered window by adding the the WS_EX_LAYERED extended style:
wndClass.ExStyle = wndClass.ExStyle | WS_EX_LAYERED;
Windows将使用黑色作为色度键颜色值.我要留下一个大的黑色边框,以使问题显而易见:
Windows will use black as the chroma key color value. i'm going to leave a large border of black to make the problem obvious:
在构建窗口之后,我告诉它使用黑色作为色度键颜色:
After the window is constructed, i tell it to use black as a chroma-key color:
SetLayeredWindowAttributes(hwnd, 0x00000000, 255, LWA_COLORKEY);
现在,弹出分层窗口显示为部分透明:
Now the popup layered window appears partially transparent:
问题是最后一步.我想使用 CS_DROPSHADOW 类样式,可用从Windows XP开始,要创建阴影:
The problem is the final step. i want to use CS_DROPSHADOW class style, available since Windows XP, to create a drop-shadow:
wndClass.Style = wndClass.Style | CS_DROPSHADOW;
出现阴影,但阴影围绕原始矩形窗口,并且未考虑分层窗口提供的窗口透明度:
The drop shadow appears, but the shadow surrounds the original rectangular window, and doesn't take into account the window's transparency provided by the layered window:
有人知道我错过了什么神奇的选择,这会使投影效果尊重非矩形分层窗口吗?
Does anyone know what magical option i've missed somewhere that will make the drop shadow honor the non-rectangular layered window?
此问题出现的另一个示例是当您不包括6px填充/边距时. Windows®绘制的提示窗口主题是非矩形的.这会在窗口透明的地方留下一个小的可见间隙,但不会出现阴影:
Another example of where this issue appears is when you don't include the 6px padding/margin. The hint window as drawn by Windows® themes is non-rectangular. This leaves a small visible gap where the window is transparent, but the drop shadow does not appear:
从Internet Explorer的此提示中可以看到,Microsoft设法使它起作用:
Microsoft has managed to make it work, as you can see from this hint from Internet Explorer:
更靠近Windows tooltips
类提示窗口.使用 SpyXX -我可以获取其窗口矩形和类样式:
Looking closer at a Windows tooltips
class hint window. Using SpyXX - i can get its window rect, and class styles:
SpyXX说:
Rectangle: (440, 229)-(544, 249), 104x20
Restored Rect: (440, 229)-(544, 249), 104x20
Client Rect: (0, 0)-(104, 20), 104x20
因此,所有指向窗口本身的像素均为104x20像素,而阴影位于窗口本身之外. (与CS_DROPSHADOW
一致.)
So everything points to the window itself being 104x20 pixels, with the drop shadow outside the window itself. (Which is consistent with CS_DROPSHADOW
.)
接下来,我可以看看tooltips
窗口类的样式:
Next i can look at the styles of the tooltips
window class:
Windows Styles: 94000001
WS_POPUP 80000000
WS_VISIBLE 10000000
WS_CLIPSIBLINGS 4000000
TTS_ALWAYSTIP 1
Extended Styles: 00080088
WS_EX_LAYERED 80000
WS_EX_TOOLWIN 80
WS_EX_TOPMOST 8
有趣的是,它不使用 CS_SAVEBITS
(0x800
);这对于短寿命的小型窗口很有用.
Interestingly, it doesn't use CS_SAVEBITS
(0x800
); which is useful for small, short-lived, windows.
它也不使用CS_DROPSHADOW
(0x20000
).所以现在我想知道它是如何在自己的窗口之外绘制的?
Nor does it use CS_DROPSHADOW
(0x20000
). So now i wonder how is it drawing outside its own window?
注意:透明的分层窗口被记录为区域上的首选技术.
Note: Transparent layered windows is documented as the preferred technique over regions.
分层Windows已出现在Windows 2000中.XP中添加了CS_DropShadow.
Layered Windows have been around with Windows 2000. CS_DropShadow was added with XP.
推荐答案
文档记录了透明分层窗口是区域上的首选技术.
Transparent layered windows is documented as the preferred technique over regions.
但是,CS_DROPSHADOW
确实注意区域.如果您使用某个区域裁剪或以其他方式塑造窗口,则阴影将遵循新轮廓.
However, CS_DROPSHADOW
does pay attention to regions. If you crop or otherwise shape your window using a region, the drop-shadow will follow the new outline.
幸运的是,您可以使用具有分层窗口的区域,并将两者结合起来即可得到您想要的效果.
Fortunately, you can use regions with layered windows, and by combining the two get the effect you're looking for.
顺便说一句:tooltips_class32 确实使用CS_DROPSHADOW-您不会在窗口样式中看到它,因为它是类样式,而不是窗口样式.
BTW: tooltips_class32 does use CS_DROPSHADOW - you won't see it in the window styles because it's a class style, not a window style.
这篇关于Win32:如何使投影荣誉非矩形“分层"窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!