C# Set Window Behind Desktop Icons

2019-04-12 15:41发布

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?

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.

Any ideas?

3条回答
淡お忘
2楼-- · 2019-04-12 16:01

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:

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.

查看更多
一纸荒年 Trace。
3楼-- · 2019-04-12 16:04

Google-fu led me to this MSDN forum question:

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)

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.

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

查看更多
Luminary・发光体
4楼-- · 2019-04-12 16:15

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 SysListView32 that 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 WindowDC to that handle and draw on the DC.

It can be done - it has been 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.

查看更多
登录 后发表回答