} // end method Desktop /// <summary> /// Captures the desktop work area to a bitmap image /// </summary> /// <returns>bitmap image of desktop work area</returns> public static Bitmap DesktopWA(Control ctl) { Rectangle wa = Screen.GetWorkingArea(ctl); // working area of screen IntPtr desktopHWND = USER32.GetDesktopWindow(); // window handle for desktop return(Window(desktopHWND, wa.X, wa.Y, wa.Width, wa.Height)); // return bitmap for desktop } // end method DesktopWA
/// <summary> /// Captures the desktop to a bitmap image /// </summary> /// <returns>bitmap image of the desktop</returns> public static Bitmap Desktop() { int width = USER32.GetSystemMetrics(USER32.SM_CXSCREEN); // width of desktop int height = USER32.GetSystemMetrics(USER32.SM_CYSCREEN); // height of desktop IntPtr desktopHWND = USER32.GetDesktopWindow(); // window handle for desktop return(Window(desktopHWND, 0, 0, width, height)); // return bitmap for desktop } // end method Desktop
} // end method Control /// <summary> /// Captures the specified area of the control or whats underneath /// the control. If the argument flag client is true, only the client /// area of the control is captured, otherwise the entire control is /// captured. If the argument flag under is true, the capture area under /// the control is captured, otherwise the specified area on the control /// is captured. /// </summary> /// <param name="ctl">Control to capture</param> /// <param name="client">If true capture only client area else entire control.</param> /// <param name="under">If true capture specified area underneath the control else whats on the control.</param> /// <returns>bitmap image of the control or whats underneath the control</returns> public static Bitmap Control(System.Windows.Forms.Control ctl, bool client, bool under) { Bitmap bmp; // capture bitmap Rectangle ctlR; // capture area rectangle in control coordinates Rectangle scrR; // capture area rectangle in screen coordinates // get capture rectangle in control // coordinates and in screen coordinates if (client) // if capturing client area { ctlR = ctl.ClientRectangle; // get rectangle in control coordinates scrR = ctl.RectangleToScreen(ctlR); // get rectangle in screen coordinates } else // if capturing entire control { scrR = ctl.Bounds; // get rectangle in parent coordinates if (ctl.Parent != null) // if parent exists { scrR = ctl.Parent.RectangleToScreen(scrR); // map to screen coordinates } ctlR = ctl.RectangleToClient(scrR); // get rectangle in control coordinates } // capture an area under the control if (under) // if capture area is under control { bool prvV = ctl.Visible; // save control visibility if (prvV) // if control visible { ctl.Visible = false; // make control invisible Thread.Sleep(m_HDelay); // allow time for control to become invisible // prior to image capture } // Capture the bitmap using desktop window handle and screen coordinates // for the capture area. Note, the control window handle can NOT be used // for capturing an area under the control. IntPtr desktopHWND = USER32.GetDesktopWindow(); // get window handle for desktop bmp = Window(desktopHWND, scrR); // get bitmap for capture area under control if (ctl.Visible != prvV) // if control visibility was changed { ctl.Visible = prvV; // restore previous visibility } } // capture an area on the control else // if capture area not under control { // Capture the bitmap using control window handle and control coordinates // for capture area. bmp = Window(ctl.Handle, ctlR); // get bitmap using control window handle } return(bmp); // return requested bitmap } // end method Control