不会被其他窗体遮挡的抓图 使用API的PrintWindow函数

射手座恶魔0

射手座恶魔0

2016-01-29 13:05

不会被其他窗体遮挡的抓图 使用API的PrintWindow函数,不会被其他窗体遮挡的抓图,使用API的PrintWindow函数

只要窗体的visable为true,即使它在屏幕的外面也可以抓到图。如果为false,就是一张黑图了,赫赫。

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;
}

API声明

[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
);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(
IntPtr hdc, // handle to DC
int nWidth, // width of bitmap, in pixels
int nHeight // height of bitmap, in pixels
);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
);
[DllImport("gdi32.dll")]
public static extern int DeleteDC(
IntPtr hdc // handle to DC
);
[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.
);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(
IntPtr hwnd );
展开更多 50%)
分享

猜你喜欢

不会被其他窗体遮挡的抓图 使用API的PrintWindow函数

电脑网络
不会被其他窗体遮挡的抓图 使用API的PrintWindow函数

在VB中使用API函数(Any)

ASP
在VB中使用API函数(Any)

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

使窗体拥有透明效果的API

C语言教程 C语言函数
使窗体拥有透明效果的API

使用API函数复制文件 可显示进度

电脑网络
使用API函数复制文件 可显示进度

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

API之绘图函数

编程语言 网络编程
API之绘图函数

API之消息函数

编程语言 网络编程
API之消息函数

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

《部落战争》正规免费刷宝石解析

《部落战争》正规免费刷宝石解析

PSV《EX棱镜骑士》白金攻略

PSV《EX棱镜骑士》白金攻略
下拉加载更多内容 ↓