http://www.pinvoke.net/default.aspx/user32/GetWindowDC.htmlDer står hvordan du ca. gør.....
her er lidt af min egen kode....
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hwnd);
[System.Runtime.InteropServices.DllImportAttribute("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.DllImportAttribute("gdi32.dll")]
private static extern IntPtr CreateDC(
string lpszDriver, // driver name
string lpszDevice, // device name
string lpszOutput, // not used; should be NULL
IntPtr lpInitData // optional printer data
);
Her er så funktionen.... den her tager bare af din form, men principet er det samme ved andre...
IntPtr screenDC = GetWindowDC(this.Handle);
// IntPtr screenDC = CreateDC("DISPLAY", null, null, (IntPtr)null);
Graphics screenGraphics = Graphics.FromHdc(screenDC);
Image MyImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, screenGraphics);
Graphics destGraphics = Graphics.FromImage(MyImage);
screenDC = screenGraphics.GetHdc();
IntPtr destDC = destGraphics.GetHdc();
BitBlt(destDC, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, screenDC, 0, 0, 13369376);
screenGraphics.ReleaseHdc(screenDC);
destGraphics.ReleaseHdc(destDC);
MyImage.Save(@"C:\Captured.jpg", ImageFormat.Jpeg);
// ouT