Reputation: 4972
How would you put a WinForms form behind desktop icons but in front of the wallpaper? To make the desktop the form's parent, I use:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
IntPtr desktopHandle = (IntPtr)FindWindow("Progman", null);
WallForm wallWindow = new WallForm();//WinForms Form
...
private void SwitchParent()
{
wallWindow.Show();
SetParent(wallWindow.Handle, desktopHandle);
//wallWindow.SendToBack();
}
This works, but it puts the form in front of the desktop icons. If I call SendToBack on my form, it disappears, presumably behind the wallpaper. How could I get the form to be between the icons and the desktop background?
Upvotes: 1
Views: 3353
Reputation: 545
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.
Upvotes: 0
Reputation: 16584
I don't believe that this is possible to do. The desktop window is a single window that renders the desktop image and the icons, so there is no way to insert your window between the desktop image and the icons.
Short of writing a shell replacement that handled the background image and desktop icons differently (a major development task with many hurdles) the only other option I can think of is to hook into the desktop's events and intercept WM_ERASEBKGND or similar to do your own drawing. (See this question or this question for more info.)
Unfortunately this won't let you put a WinForm behind the icons, only an image. You'd have to handle a lot of other windows messages to simulate an actual form. It's a major undertaking regardless.
Upvotes: 3