Re: Screen capture
From: Andrew Arace (AndrewRArace_at_gmail.com)
Date: 01/17/05
- Next message: Aung: "Re: help with formatting string"
- Previous message: Nicholas Yue: "Launching C# console application from another [legacy] application"
- In reply to: Per: "Screen capture"
- Messages sorted by: [ date ] [ thread ]
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;
}
}
- Next message: Aung: "Re: help with formatting string"
- Previous message: Nicholas Yue: "Launching C# console application from another [legacy] application"
- In reply to: Per: "Screen capture"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|