C# 截取窗口图像(包括遮挡窗口,最小化窗口)

   

        [DllImport("user32.dll")]
        public static extern bool PrintWindow(
         IntPtr hwnd,               // Window to copy,Handle to the window that will be copied. 
         IntPtr hdcBlt,             // HDC to print into,Handle to the device context. 
         UInt32 nFlags              // Optional flags,Specifies the drawing options. It can be one of the following values. 
         );

 

            //传入窗口句柄,获取该窗口的图像信息

       private Image GetWindowImage(IntPtr windownHandle)
       {
          Control control =Control.FromHandle(windownHandle);
          Bitmap image = new Bitmap(control.Width, control.Height);
          Graphics gp = Graphics.FromImage(image); 
          IntPtr dc = gp.GetHdc();
          PrintWindow(windownHandle, dc, 0);
          gp.ReleaseHdc();
          gp.Dispose();
          return image;
       }

 

posted @ 2013-04-12 22:29  逍遥子k  阅读(1891)  评论(0编辑  收藏  举报