private void Cleanup(int hBitmap, int hdcSrc, int hdcDest)
 {
     User32.ReleaseDC(User32.GetDesktopWindow(), hdcSrc);
     GDI32.DeleteDC(hdcDest);
     GDI32.DeleteObject(hBitmap);
 }
        /// <summary>
        /// Creates an Image object containing a screen shot of the entire desktop
        /// </summary>
        /// <returns></returns>
        public void CaptureScreen(string fileName, ImageFormat imageFormat)
        {
            int hdcSrc  = User32.GetWindowDC(User32.GetDesktopWindow()),
                hdcDest = GDI32.CreateCompatibleDC(hdcSrc),
                hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,
                                                       GDI32.GetDeviceCaps(hdcSrc, 8), GDI32.GetDeviceCaps(hdcSrc, 10)); GDI32.SelectObject(hdcDest, hBitmap);

            GDI32.BitBlt(hdcDest, 0, 0, GDI32.GetDeviceCaps(hdcSrc, 8),
                         GDI32.GetDeviceCaps(hdcSrc, 10), hdcSrc, 0, 0, 0x00CC0020);

            SaveImageAs(hBitmap, fileName, imageFormat);
            Cleanup(hBitmap, hdcSrc, hdcDest);
        }