在桌面背景上绘图作为壁纸替换 (Windows/C#)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1683791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Drawing on the desktop background as wallpaper replacement (Windows/C#)
提问by nardi
I'm trying to make an application that needs to draw on the desktop, behind the icons so it appears to replace the desktop wallpaper. I've found a few solutions to this, but most of them didn't work very well (lots of flickering). One solution seems to be what I'm looking for, but I don't really get it. I've done mostly C# applications using either higher-level graphics libraries or just Windows Forms, and some C++ but only on non-Windows platforms.
我正在尝试制作一个需要在桌面上绘制的应用程序,位于图标后面,因此它似乎可以替换桌面墙纸。我已经找到了一些解决方案,但大多数都不能很好地工作(大量闪烁)。一种解决方案似乎是我正在寻找的,但我真的不明白。我主要使用高级图形库或仅使用 Windows 窗体和一些 C++ 完成 C# 应用程序,但仅在非 Windows 平台上。
If anyone could "translate" it for me or provide me with an alternative solution, it would be much appreciated!
如果有人可以为我“翻译”它或为我提供替代解决方案,将不胜感激!
采纳答案by nardi
I never found the solution I wanted, but here are the best (only?) alternatives:
我从来没有找到我想要的解决方案,但这里有最好的(唯一的?)替代方案:
Draw to the "SysListView32" window (ProgMan -> SHELLDLL_DefView -> SysListView32). This will draw behind the desktop icons, but will flicker when animation is used. How to: Link(you'll have to use interop in .NET).
Use DirectDraw overlays. You set the desktop color to a certain obscure color and everything with that color will be replaced with what's on the overlay. This is used in the example in my question and in the VLC wallpaper mode. However, this is incompatible with Aero. How to: Link(I guess you could use Managed DirectX in .NET?).
回答by Géal
You can find inspiration in the VLC media player code. there's a wallpaper modethat does what you're looking for.
您可以在 VLC 媒体播放器代码中找到灵感。有一种壁纸模式可以满足您的需求。
回答by William Dutton
Seen this question in passing and I did partially solve the problem (But not in a way I can give any useful code) to make some cool games although might not have the application you want:
顺便看到这个问题,我确实部分解决了这个问题(但我不能提供任何有用的代码)来制作一些很酷的游戏,尽管可能没有你想要的应用程序:
- Set desktop background back to normal and take a screenshot of the desktop
- Set desktop background black and take a screenshot of the desktop
- Set desktop background white and take a screenshot of the desktop
- Combine the black and white versions to make a mask and the first screenshot as the overlay setting pixel values that are different transparent.
- 将桌面背景恢复正常并截取桌面
- 将桌面背景设置为黑色并截取桌面
- 将桌面背景设置为白色并截取桌面
- 结合黑白版本制作蒙版和第一张截图作为叠加设置不同透明的像素值。
Now on your form draw the following in order:
现在在您的表单上按顺序绘制以下内容:
- Draw the first screenshot
- Draw your form stuff
- Draw the desktop overlay you created
- 绘制第一个屏幕截图
- 绘制你的表单
- 绘制您创建的桌面覆盖
This is what I did for a full screen form but could be adapted for non full screen forms quite easily I think. Essentially you have recreated the desktop but with the ability to do anything with it including some cool games. The draw speed and performance is satisfactory for any application but desktop interactivity is an issue... :( Here is a pic of a tanks game using the principle except I set the background white and made all white backgrounds transparent too!
这是我为全屏形式所做的,但我认为可以很容易地适应非全屏形式。从本质上讲,您已经重新创建了桌面,但可以用它做任何事情,包括一些很酷的游戏。任何应用程序的绘制速度和性能都令人满意,但桌面交互性是一个问题...... :( 这是一张坦克游戏的图片,使用该原理,除了我将背景设置为白色并使所有白色背景也透明!