Re: Screen capture

From: Andrew Arace (AndrewRArace_at_gmail.com)
Date: 01/17/05


Date: 17 Jan 2005 06:21:20 -0800

I can't help you on the mouse pointer click simulation,
but i can provide you with some screen capture code:

public class ImagingUtils {

//imports the GDI BitBlt function that enables the background
of the window
//to be captured
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);

[System.Runtime.InteropServices.DllImport("User32.dll")]
public extern static System.IntPtr GetDC(System.IntPtr hWnd);

[System.Runtime.InteropServices.DllImport("User32.dll")]
public extern static int ReleaseDC(System.IntPtr hWnd,
System.IntPtr hDC); //modified to include hWnd

/// <summary>
/// Returns a full desktop screencapture
/// </summary>
/// <returns>A Bitmap object capture of the entire
desktop.</returns>
public static Image GetScreenCapture() {
System.IntPtr desktopDC = GetDC(System.IntPtr.Zero);
Bitmap bm = new
Bitmap(System.Windows.Forms.SystemInformation.VirtualScreen.Width,

System.Windows.Forms.SystemInformation.VirtualScreen.Height);
Graphics g = Graphics.FromImage(bm);
System.IntPtr bmDC = g.GetHdc();
BitBlt(bmDC, 0, 0, bm.Width,bm.Height, desktopDC, 0, 0,
0x00CC0020 /*SRCCOPY*/);
ReleaseDC(System.IntPtr.Zero, desktopDC);
g.ReleaseHdc(bmDC);
g.Dispose();
return bm;
}

/// <summary>
/// Returns a capture of the control's current graphics.
/// </summary>
/// <param name="ctrl">The winforms control to capture</param>
/// <returns>A Bitmap object of the captured graphics</returns>
public static Image
GetControlImageCapture(System.Windows.Forms.Control ctrl) {
System.IntPtr ctrlCapture = GetDC(ctrl.Handle);
Bitmap bm = new Bitmap(ctrl.Width,
ctrl.Height);
Graphics g = Graphics.FromImage(bm);
System.IntPtr bmDC = g.GetHdc();
BitBlt(bmDC, 0, 0, bm.Width, bm.Height, ctrlCapture, 0, 0,
0x00CC0020 /*SRCCOPY*/);
ReleaseDC(ctrl.Handle, ctrlCapture);
g.ReleaseHdc(bmDC);
g.Dispose();
            return bm;
        }

        }



Relevant Pages

  • Re: Question about printing
    ... int nXDest, // x-coord of destination upper-left corner ... > control and graphics can not be drawed with this class. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Print Form Properly?
    ... which is not what I want - I only want the screen dump of ... int nXDest, // x-coord of destination upper-left corner ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Grabbing content in controller or form to a image
    ... It works as long as the window with the control is visible. ... int nXDest, // x-coord of destination upper-left corner ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Problem using SP_TRACE_SETFILTER - it doesnt seem to apply th
    ... @bigintfilter and @intfilter input parameters) because of the nature of the ... @duration int, -- in minutes ... 1.04 - customised to capture specific information for PrecisDM ... exec master.dbo.xp_cmdshell @RenameCmd,NO_OUTPUT ...
    (microsoft.public.sqlserver.server)
  • [PATCH] usbmon: control the max amount of captured data for eachurb
    ... An ioctl method is added to each usbmon text files. ... capture for each URB, and changing this value. ... char setup_flag; ... - int len, char ev_type) ...
    (Linux-Kernel)

Quantcast