使用下面的函数:public Bitmap CaptureDesktopWindow()
{
//创建屏幕句柄
// Graphics grpWindow =Graphics.FromHwnd(IntPtr.Zero);
Graphics grpWindow=this.CreateGraphics();
Bitmap bitmap = new Bitmap((int)grpWindow.VisibleClipBounds.Width, (int)grpWindow.VisibleClipBounds.Height, grpWindow);
Graphics grpBitmap = Graphics.FromImage(bitmap);
IntPtr hdcWindow = grpWindow.GetHdc();
IntPtr hdcBitmap = grpBitmap.GetHdc();
Gdi32.BitBlt(hdcBitmap, 0, 0, bitmap.Width, bitmap.Height, hdcWindow, 0, 0, 0x00CC0020);
grpBitmap.ReleaseHdc(hdcBitmap);
grpWindow.ReleaseHdc(hdcWindow); grpBitmap.Dispose();
grpWindow.Dispose(); return bitmap;
}
得到屏幕图象,在非MDI窗体下运行正常,但是如果是MDI自窗体的话捕捉到的图象总是MDI应用程序Z序后面那个图象,也就是如果只运行了一个MDI程序那捕捉到的就是桌面背景。而且当前窗口显示的还是这个MDI程序,实在不知道是什么原因了。
{
//创建屏幕句柄
// Graphics grpWindow =Graphics.FromHwnd(IntPtr.Zero);
Graphics grpWindow=this.CreateGraphics();
Bitmap bitmap = new Bitmap((int)grpWindow.VisibleClipBounds.Width, (int)grpWindow.VisibleClipBounds.Height, grpWindow);
Graphics grpBitmap = Graphics.FromImage(bitmap);
IntPtr hdcWindow = grpWindow.GetHdc();
IntPtr hdcBitmap = grpBitmap.GetHdc();
Gdi32.BitBlt(hdcBitmap, 0, 0, bitmap.Width, bitmap.Height, hdcWindow, 0, 0, 0x00CC0020);
grpBitmap.ReleaseHdc(hdcBitmap);
grpWindow.ReleaseHdc(hdcWindow); grpBitmap.Dispose();
grpWindow.Dispose(); return bitmap;
}
得到屏幕图象,在非MDI窗体下运行正常,但是如果是MDI自窗体的话捕捉到的图象总是MDI应用程序Z序后面那个图象,也就是如果只运行了一个MDI程序那捕捉到的就是桌面背景。而且当前窗口显示的还是这个MDI程序,实在不知道是什么原因了。
Graphics grpWindow=this.CreateGraphics();
这句话的意思,你是要捕捉当前窗体的图形?
原来是用Graphics grpWindow =Graphics.FromHwnd(IntPtr.Zero);也是不行?
http://community.csdn.net/Expert/topic/4589/4589829.xml?temp=.9946863
http://www.syncfusion.com/faq/windowsforms/search/625.aspx