public static GDIContext CreateForDesktopBackground()
{
IntPtr hDC = IntPtr.Zero;
// First get a handle on the Program Manager window using FindWindow
IntPtr hProgMan = User32.FindWindow("ProgMan", null);
if (IntPtr.Zero != hProgMan)
{
// The only child of this window is the Shell Window
// So get that handle.
IntPtr hShellView = User32.GetWindow(hProgMan, User32.GW_CHILD);
// Now that we have the shell window, get the ListView, which is the
// child displaying everything.
IntPtr hListView = User32.GetWindow(hShellView, User32.GW_CHILD);
// Finally, get the DeviceContext handle for this list view
hDC = User32.GetDC(hListView);
}
else
{
// If null was returned, then we're probably on Vista, and need to ask for
// The "Program Manager" window.
if (IntPtr.Zero == hProgMan)
{
hProgMan = User32.FindWindow("Program Manager", null);
hDC = User32.GetDC(hProgMan);
}
}
// And create a GDIContext for it
GDIContext aContext = new GDIContext(hDC, false);
return aContext;
}