资源简介
windows下的抓屏组件包含了GDI,DDRAW和DXGI等多种技术的抓屏代码
代码片段和文件信息
#include “../stdafx.h“
#include “VideoDxCaptor.h“
#include
#pragma comment(lib “Dwmapi.lib“)
VideoDXCaptor::VideoDXCaptor(void)
{
m_lpDDraw = NULL;
m_lpDDSPrime = NULL;
m_lpDDSBack = NULL;
}
VideoDXCaptor::~VideoDXCaptor(void)
{
Deinit();
}
BOOL VideoDXCaptor::Init()
{
HMODULE hDll = LoadLibrary(“ddraw.dll“);
if (hDll == NULL)
{
(“无法载入ddraw.dll\n“);
return FALSE;
}
// 载入ddraw的导入函数
PFN_DirectDrawCreate DirectDrawCreateFunc = (PFN_DirectDrawCreate)GetProcAddress(hDll “DirectDrawCreate“);
if (DirectDrawCreateFunc == NULL)
{
(“无法找到访问点:DirectDrawCreate\n“);
return FALSE;
}
HRESULT hr = DirectDrawCreateFunc(NULL &m_lpDDraw NULL);
if (FAILED(hr))
{
(“DirectDrawCreate失败\n“);
return FALSE;
}
hr = m_lpDDraw->SetCooperativeLevel(NULL DDSCL_NORMAL);
if (FAILED(hr))
{
(“SetCooperativeLevel失败\n“);
return FALSE;
}
DDSURFACEDESC DDSdesc;
ZeroMemory(&DDSdesc sizeof(DDSdesc));
DDSdesc.dwSize = sizeof(DDSdesc);
DDSdesc.dwFlags = DDSD_CAPS;
DDSdesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = m_lpDDraw->CreateSurface(&DDSdesc &m_lpDDSPrime NULL);
if (FAILED(hr))
{
(“CreateSurface 主表面失败\n“);
return FALSE;
}
ZeroMemory(&DDSdesc sizeof(DDSdesc));
DDSdesc.dwSize = sizeof(DDSdesc);
DDSdesc.dwFlags = DDSD_ALL;
hr = m_lpDDSPrime->GetSurfaceDesc(&DDSdesc);
if (FAILED(hr))
{
(“GetSurfaceDesc失败\n“);
return FALSE;
}
// 备份描述信息
memcpy(&m_DDSdesc &DDSdesc sizeof(DDSdesc));
DDSdesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
DDSdesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
hr = m_lpDDraw->CreateSurface(&DDSdesc &m_lpDDSBack 0);
if (FAILED(hr))
{
(“CreateSurface 后备表面失败\n“);
return FALSE;
}
return TRUE;
}
VOID VideoDXCaptor::Deinit()
{
if (m_lpDDSBack)
{
m_lpDDSBack->Release();
m_lpDDSBack = NULL;
}
if (m_lpDDSPrime)
{
m_lpDDSPrime->Release();
m_lpDDSPrime = NULL;
}
if (m_lpDDraw)
{
m_lpDDraw->Release();
m_lpDDraw = NULL;
}
}
BOOL VideoDXCaptor::CaptureImage(RECT &rect void *pData INT &nLen)
{
if (m_lpDDSBack == NULL)
{
(“DDraw对象未初始化\n“);
return FALSE;
}
HRESULT hr = m_lpDDSBack->BltFast(rect.left rect.top m_lpDDSPrime &rect DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
if (FAILED(hr))
{
(“BltFast失败\n“);
return FALSE;
}
DDSURFACEDESC surfDesc;
ZeroMemory(&surfDesc sizeof(surfDesc));
surfDesc.dwSize = sizeof(surfDesc);
//hr = lpDDSPrime->Lock(&rect &surfdesc DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR NULL);
hr = m_lpDDSBack->Lock(&rect &surfDesc DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR NULL);
if (FAILED(hr))
{
(“Lock失败\n“);
return FALSE;
}
// 这里拷贝的是32位数据,我们只需要24位的RGB数据
//memcpy(pBuf (BYTE*)surfDesc.lpSurface surfDesc.dwWidth * surfDesc.dwHeight * surfDesc.ddpfPixelFormat.dwRGBBitCount / 8);
// 将抓上来的图像转成RGB数据(
相关资源
- AE开发Windows最短路径分析
-
Windows em
bedded Compact 2013 应用开发调 - 黑苹果硬件兼容检测和查询软件
- Uninstall_Cortana_WINCLIENT.CN.rar
- VMware65_SLP_DeLLSLIC2.1
- Windows异步套接字网络编程
- WINDOWS98启动盘镜像Win98.IMA
- 仿windows记事本
- GDI自绘滚动条
- windows7用的,非常漂亮的透明计时器
- windows下制作macOS安装U盘,绝对简单好
- keil vcom windows 7 64bit 驱动
- windows ce 系统的GPIO驱动程序
- TCP 发包工具(windows)
- 微软的可以删除系统卸不干净的软件
- windows下生成MD5值的工具(WinMD5)
- windows cygwin ns2安装步骤
- VC 使用GDI 矢量绘图软件源代码
- WinAPI 函数库(大全)
- 解决在Windows XP SP2下不能显示验证码的
- 加快Windows XP操作系统开机速度
- 易语言矩阵的旋转源码易语言GDI矩阵
- 易语言认识矩阵源码易语言GDI矩阵源
- 易语言矩阵应用到指定坐标源码易语
- Windows 1.0 软盘镜像
- Windows下访问LINUX的利器-SSH
- ChilledWindows.exe(玩笑病毒)
- NDK-R12B windows-x86_64百度云盘
- windows3.2简体中文版,虚拟机文件
- Windows 3.0 安装软盘(3.5 720k)
评论
共有 条评论