DwmExtendFrameIntoClientArea 没有 TransparencyKey?
使用 DwmExtendFrameIntoClientArea
函数时,我需要选择 Form.TransparencyKey
,这是绘制玻璃的颜色。
问题是我编写图像编辑工具,当 TransparencyKey
颜色出现在编辑的图像内时,用户看到的是玻璃。
如何将玻璃延伸到客户区域而不损失一些颜色?
When using DwmExtendFrameIntoClientArea
function I need to choose Form.TransparencyKey
, a color that a glass will be drawn on instead.
The problem is that i writing image-edit tool, and when TransparencyKey
color appear inside the edited image, the user see glass instead.
How do i extend the glass into client area without losing some color?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有理由将
Form.TransparencyKey
属性与 DWM 函数一起使用。该属性与分层窗口有关,与 Aero 玻璃效果无关。我认为它可能起作用的事实更多是实现细节的结果(例如您设置为 TransparencyKey 的颜色的所有 3 个 RGB 值都是相同的),而不是设计使然。GDI 将黑色视为透明颜色,因此您应该只使用黑色画笔绘制要显示为玻璃的窗体的特定区域。因为您将黑色填充仅限于这些区域,所以这不会干扰 UI 的其余部分。
当然,出现在您渲染为玻璃的区域中的任何黑色文本(例如在控件上绘制的文本)都会看起来很难看。解决方案是切换到基于 GDI+ 的渲染,或者将控件移到要渲染为玻璃的区域之外。如果您需要比
DwmExtendFrameIntoClientArea
提供的表单区域(实际上只是将框架扩展一定量)更好地控制显示为玻璃状的区域,请考虑使用DwmEnableBlurBehindWindow
代替。请参阅我的更完整的在这里回答如何使用该功能。There's no reason you should be using the
Form.TransparencyKey
property with DWM functions. That property relates to layered windows, which has nothing to do with the Aero glass effect. I assume the fact that it might work is more a consequence of implementation detail (like all 3 RGB values of the color you've set as theTransparencyKey
are the same), rather than by design.GDI treats black as the transparency color, so you should just paint the particular regions of your form that you want to appear as glass with a black brush. Because you're limiting the black fill to only those areas, there's no reason this should interfere with the rest of your UI.
Of course, any black text (such as that drawn on controls) that appears in the area you're rendering as glass is going to look ugly. The solution is either to switch to GDI+-based rendering or to move your controls outside of the area to be rendered as glass. If you need finer control over the area of your form that should appear glassy than provided by
DwmExtendFrameIntoClientArea
(which literally just extends the frame by a set amount), look into usingDwmEnableBlurBehindWindow
instead. See my more complete answer here on how to use that function.