GDIIMAGE_PLUS.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Drawing;
/*
 Note:利用此函数截取任何窗体的内容,即使窗体被遮盖(但窗体必须是非最小化状态)
 Author:stardance
 Date:2018-04-04
 Addr:Anhui WuHu
 */

using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowCaptureDemo
{
    
    class GDIIMAGE_PLUS
    {
        public static Bitmap GetWindow(IntPtr hWnd)
        {
            IntPtr hscrdc = GetWindowDC(hWnd);
            Control control = Control.FromHandle(hWnd);
            IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, control.Width, control.Height);
            IntPtr hmemdc = CreateCompatibleDC(hscrdc);
            SelectObject(hmemdc, hbitmap);
            PrintWindow(hWnd, hmemdc, 0);
            Bitmap bmp = Bitmap.FromHbitmap(hbitmap);
            DeleteDC(hscrdc);//删除用过的对象
            DeleteDC(hmemdc);//删除用过的对象
            return bmp;
        }

        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateDC(
        string lpszDriver,        // driver name驱动名
        string lpszDevice,        // device name设备名
        string lpszOutput,        // not used; should be NULL
        IntPtr lpInitData  // optional printer data
        );

        [DllImport("gdi32.dll")]
        public static extern int BitBlt(
        IntPtr hdcDest, // handle to destination DC目标设备的句柄
        int nXDest,  // x-coord of destination upper-left corner目标对象的左上角的X坐标
        int nYDest,  // y-coord of destination upper-left corner目标对象的左上角的Y坐标
        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源对象的左上角的X坐标
        int nYSrc,   // y-coordinate of source upper-left corner源对象的左上角的Y坐标
        UInt32 dwRop  // raster operation code光栅的操作值
   );

        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateCompatibleDC(
        IntPtr hdc // handle to DC
  );
后面还有 32 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。