windows C# 在桌面图标后面设置窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1978077/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:40:10  来源:igfitidea点击:

C# Set Window Behind Desktop Icons

c#windowswinapihandle

提问by Ozzy

Assume i have an empty form 100px by 100px at 0,0 coordinates on the screen. It has no border style. Is there any way to have this positioned BEHIND the desktop icons?

假设我在屏幕上的 0,0 坐标处有一个 100px x 100px 的空表单。它没有边框样式。有什么办法可以把它放在桌面图标的后面?

I would assume this would involve the process Progman because thats what contains the desktop icons. But no matter what i try... getting window handles and changing parents etc, i cant seem to get the window to appear behind the icons.

我认为这将涉及进程 Progman,因为那是包含桌面图标的内容。但是无论我尝试什么...获取窗口句柄和更改父项等,我似乎无法让窗口出现在图标后面。

Any ideas?

有任何想法吗?

采纳答案by Aaronaught

Essentially you want to draw on the desktop wallpaper. The desktop hierarchy looks like this:

基本上你想在桌面壁纸上画画。桌面层次结构如下所示:

"Program Manager" Progman
  "" SHELLDLL_DefView
    "FolderView" SysListView32

It's the SysListView32that actually draws the desktop icons, so that's what you have to hook. And you can't just stick your form on top of it; you have to grab a WindowDCto that handle and draw on the DC.

SysListView32是实际绘制桌面图标的 ,所以这就是你必须挂钩的。你不能只是把你的表格贴在上面;你必须抓住WindowDC那个手柄并在 DC 上画画。

It canbe done - it hasbeen done, but you're going to be using a lot of interop. Forget about doing this with a traditional Winforms Form. I don't think I've even seen it done in C#, although somebody did it in python, if that helps. I'm not a python coder myself, but the code is pretty short and easy to understand.

可以做-它已经做了,但你要使用大量的互操作的。忘记使用传统的 Winforms 表单执行此操作吧。我认为我什至没有看到它在 C# 中完成,尽管有人在python 中完成了它,如果有帮助的话。我本人不是 Python 编码员,但代码非常简短且易于理解。

回答by Gerald Degeneve

There is a solution to this problem, at least for Windows 8. I postet it in form of an article on CodeProject, so you can read about it here:

这个问题有一个解决方案,至少对于 Windows 8。我以一篇关于 CodeProject 的文章的形式发布了它,所以你可以在这里阅读它:

http://www.codeproject.com/Articles/856020/Draw-behind-Desktop-Icons-in-Windows

http://www.codeproject.com/Articles/856020/Draw-behind-Desktop-Icons-in-Windows

This works for simple drawing, windows forms, wpf, directx, etc. The solution presented in that article is only for Windows 8.

这适用于简单绘图、windows 窗体、wpf、directx 等。该文章中提供的解决方案仅适用于 Windows 8。

回答by Alastair Pitts

Google-fu led me to this MSDN forum question:

Google-fu 把我带到了这个 MSDN 论坛问题:

http://social.msdn.microsoft.com/Forums/en/winformsdesigner/thread/c61d0705-d9ec-436a-b0a6-6ffa0ecec0cc

http://social.msdn.microsoft.com/Forums/en/winformsdesigner/thread/c61d0705-d9ec-436a-b0a6-6ffa0ecec0cc

And this is a blog post regard the major pitfalls with using GetDesktopWindow() or dealing with the desktop handle (as per your other question: C# Position Window On Desktop)

这是一篇关于使用 GetDesktopWindow() 或处理桌面句柄的主要陷阱的博客文章(根据您的另一个问题:C# Position Window On Desktop

http://blogs.msdn.com/oldnewthing/archive/2004/02/24/79212.aspx

http://blogs.msdn.com/oldnewthing/archive/2004/02/24/79212.aspx

You also don't want to pass GetDesktopWindow() as your hwndParent. If you create a child window whose parent is GetDesktopWindow(), your window is now glued to the desktop window. If your window then calls something like MessageBox(), well that's a modal dialog, and then the rules above kick in and the desktop gets disabled and the machine is toast.

您也不希望将 GetDesktopWindow() 作为您的 hwndParent 传递。如果您创建一个父窗口为 GetDesktopWindow() 的子窗口,您的窗口现在粘在桌面窗口上。如果您的窗口然后调用类似 MessageBox() 的东西,那么这就是一个模态对话框,然后上面的规则开始生效,桌面被禁用,机器吐司。

Anyway, I suspect that it probably CAN be done, but whether you should is another question.

无论如何,我怀疑它可能可以完成,但你是否应该是另一个问题。