NewTOAPIA.Drawing.GDI.GDIContext.CreateForDesktopBackground C# (CSharp) 메소드

CreateForDesktopBackground() 공개 정적인 메소드

Create a GDIContext so that drawing to the desktop can occur. On Vista, the drawing will be behind all windows, but will draw on top of any icons on the actual desktop. For Windows XP, the drawing will be behind those icons as well.
public static CreateForDesktopBackground ( ) : GDIContext
리턴 GDIContext
        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;

        }