屏幕捕捉技术第一步就是抓取屏幕的桌面
虽然print screen键可以,但是在实际中就有点不适用了
下面的代码可以拷贝到一个函数里面,执行就可以生成一个获取屏幕的bmp文件了
//获取桌面窗口的CDC
CDC *pdeskdc = GetDesktopWindow()->GetDC();
CRect re;
//获取窗口的大小
GetDesktopWindow()->GetClientRect(&re);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pdeskdc , re.Width() , re.Height());
//创建一个兼容的内存画板
CDC memorydc;
memorydc.CreateCompatibleDC(pdeskdc);
//选中画笔
CBitmap *pold = memorydc.SelectObject(&bmp);
//绘制图像
memorydc.BitBlt(0,0,re.Width() ,re.Height(), pdeskdc , 0 ,0 ,SRCCOPY) ;
//获取鼠标位置,然后添加鼠标图像
CPoint po;
GetCursorPos(&po);
HICON hinco = (HICON)GetCursor();
memorydc.DrawIcon(po.x-10 , po.y - 10 , hinco);
//选中原来的画笔
memorydc.SelectObject(pold);
BITMAP bit;
bmp.GetBitmap(&bit);
// DWORD size = bit.bmWidth * bit.bmHeight ;
//定义 图像大小(单位:byte)
DWORD size = bit.bmWidthBytes * bit.bmHeight ;
LPSTR lpda