/// <summary>
        /// Captures a screenshot of a window using Windows GDI
        /// </summary>
        /// <param name="handle">handle of the window to capture</param>
        /// <returns>the captured window image</returns>
        public static Image CaptureWithGDI(IntPtr handle)
        {
            FileSystem.AppendDebug("Capturing with GDI");
            Rectangle windowRect;

            if (Engine.conf.ActiveWindowTryCaptureChildren)
            {
                windowRect = new WindowRectangle(handle).CalculateWindowRectangle();
            }
            else
            {
                windowRect = NativeMethods.GetWindowRectangle(handle);
            }

            windowRect = NativeMethods.MaximizedWindowFix(handle, windowRect);

            FileSystem.AppendDebug("Window rectangle: " + windowRect.ToString());

            Image windowImage = null;

            if (Engine.conf.ActiveWindowClearBackground)
            {
                windowImage = CaptureWindowWithTransparencyGDI(handle, windowRect);
            }

            if (windowImage == null)
            {
                using (new Freeze(handle))
                {
                    windowImage = CaptureRectangle(windowRect);
                }

                if (Engine.conf.ActiveWindowCleanTransparentCorners)
                {
                    Image result = RemoveCorners(handle, windowImage, null, windowRect);
                    if (result != null)
                    {
                        windowImage = result;
                    }
                }

                if (Engine.conf.ActiveWindowIncludeShadows)
                {
                    // Draw shadow manually to be able to have shadows in every case
                    windowImage = GraphicsMgr.AddBorderShadow((Bitmap)windowImage, true);
                }

                if (Engine.conf.ShowCursor)
                {
                    DrawCursor(windowImage, windowRect.Location);
                }
            }

            return(windowImage);
        }
        /// <summary>
        /// Captures a screenshot of a window using the Windows DWM
        /// </summary>
        /// <param name="handle">handle of the window to capture</param>
        /// <returns>the captured window image</returns>
        public static Image CaptureWithDWM(IntPtr handle)
        {
            FileSystem.AppendDebug("Capturing with DWM");
            Image  windowImage = null;
            Bitmap redBGImage  = null;

            Rectangle windowRect = NativeMethods.GetWindowRectangle(handle);

            windowRect = NativeMethods.MaximizedWindowFix(handle, windowRect);

            if (Engine.HasAero && Engine.conf.ActiveWindowClearBackground)
            {
                windowImage = CaptureWindowWithTransparencyDWM(handle, windowRect, out redBGImage, Engine.conf.ActiveWindowCleanTransparentCorners);
            }

            if (windowImage == null)
            {
                FileSystem.AppendDebug("Standard capture (no transparency)");
                windowImage = CaptureRectangle(windowRect);
            }

            if (Engine.conf.ActiveWindowCleanTransparentCorners)
            {
                Image result = RemoveCorners(handle, windowImage, redBGImage, windowRect);
                if (result != null)
                {
                    windowImage = result;
                }
            }

            if (windowImage != null)
            {
                if (Engine.conf.ActiveWindowIncludeShadows)
                {
                    // Draw shadow manually to be able to have shadows in every case
                    windowImage = GraphicsMgr.AddBorderShadow((Bitmap)windowImage, true);
                    Point shadowOffset = GraphicsMgr.ShadowOffset;
                    windowRect.X -= shadowOffset.X;
                    windowRect.Y -= shadowOffset.Y;
                }

                if (Engine.conf.ActiveWindowShowCheckers)
                {
                    windowImage = ImageEffects.DrawCheckers(windowImage);
                }

                if (Engine.conf.ShowCursor)
                {
                    DrawCursor(windowImage, windowRect.Location);
                }
            }

            return(windowImage);
        }