在 Windows 上绘制叠加图形的最佳方法是什么?
我正在使用需要创建各种自定义窗口类型的 Win32 应用程序。特别是,这些窗口通常不是矩形,有阴影,或者大部分是透明的。
我目前正在使用 WS_EX_LAYERED
和 UpdateLayeredWindow
来创建透明窗口,然后我可以在上面绘制任意图形。但是,我发现分层窗口存在局限性,因为您不能拥有分层子窗口,分层窗口也不能正确托管“普通”Win32 控件。
我们的代码库已经有好几年了,主要使用 Win32 和 GDI,但我们正处于现代化的过程中,是时候考虑更新的技术了。
我考虑过在 WPF 中进行自定义窗口,但我担心我读到的有关“空域”问题的内容。 WPF 似乎使用分层窗口来完成其每像素 alpha 混合,因此它似乎也会受到我之前遇到的限制的影响。
我对 Direct2D 了解不多(真的什么都不知道),但该技术听起来可能很有趣。不过,我找不到任何关于它能够覆盖窗口的参考。
所以,所有这些都让我想到了我的问题:在 Windows 下执行覆盖窗口的最佳技术是什么? (至少有Vista和Win7,XP就更好了)
我是否忽略了一些特别好的技术?任何建议将不胜感激。
I'm working with a Win32 application that needs to create a variety of custom window types. In particular, these windows are often non-rectangle, have shadows, or are mostly transparent.
I'm currently using WS_EX_LAYERED
with UpdateLayeredWindow
to create transparent windows that I can then draw my arbitrary graphics on. However, I find layered windows to be limiting in that you can't have layered child windows, nor can a layered window properly host 'normal' Win32 controls.
Our code base is several years old, using mostly Win32 and GDI, but we're in the process of modernizing things and it's time to look at newer technologies.
I've considered doing my custom windowing in WPF, but I'm concerned about what I've read about 'airspace' issues. It seems that WPF uses layered windows to accomplish its per-pixel alpha blending and so seems like it would also suffer from the limitations I've previously experienced.
I don't know much (anything, really) about Direct2D, but that technology sounds like it might be interesting. Though, I can't find any references to it being able to do overlay windows.
So, all of this brings me to my problem: What's the best technology for doing overlay windows under Windows? (Vista and Win7 at a minimum, XP would be nice to have)
Am I neglecting some, particularly good technology? Any suggestions would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WPF 可以非常轻松地完成您正在寻找的任务,但是,由于图形驱动程序错误,WPF 的这一特殊功能(具有每像素透明度的窗口)往往会产生很大的问题(显然图形硬件制造商不会使用每像素测试分层 Direct3D 窗口)像素 alpha 值非常好)。
WPF 确实使用分层窗口来实现透明度,但它不使用“普通”win32 控件,窗口中的所有 wpf 控件仅使用一个 win32 窗口自行渲染,它们都支持透明度。
仅当您在 WPF 窗口内托管 WinForms 控件时,才会出现“空域”问题。
WPF can do what you are looking for very easily, but, this particular feature of WPF (windows with per-pixel transparency) tends to be very problematic due to graphics drivers bugs (apparently graphic hardware manufacturers don't test layered Direct3D windows with per pixel alpha value very well).
WPF does use layered windows for transparency, but it does not use "normal" win32 controls, all the wpf controls in a window render them self using just one win32 window, they all support transparency.
The "airspace" issue only happens when you host a WinForms control inside a WPF window.
我推荐 Direct2D 和 DirectWrite,因为您可以获得高质量的渲染,而且与 GDI 或 .Net 空间中完成的任何操作相比,速度也快得惊人。唯一的问题是您需要 Vista 或更高版本的操作系统才能使用它。
I recommend Direct2D and DirectWrite as you get high-quality rendering that's also ridiculously fast compared to either GDI or anything done in the .Net space. The only problem is that you need Vista or later OS to use it.