int _tmain(int argc, _TCHAR* argv[])
{
//获取屏幕DC
HDC hDesktopDC = CreateDC(L"DISPLAY", NULL, NULL, NULL);
//内存DC
HDC hMemoryDC = CreateCompatibleDC(hDesktopDC);
//得到屏幕宽度
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
//根据屏幕DC创建屏幕位图
HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight);
//将位图选择到内存DC中
SelectObject(hMemoryDC, hCaptureBitmap);
//将屏幕DC传送到内存DC中
BitBlt(hMemoryDC, 0, 0, nScreenWidth, nScreenHeight, hDesktopDC, 0, 0, SRCCOPY);
//得到鼠标位置
POINT pt;
GetCursorPos(&pt);
//加载鼠标位图
HCURSOR m_hcursor = LoadCursor(NULL, IDC_ARROW);
DrawIconEx(hMemoryDC, pt.x, pt.y, m_hcursor, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT);
SelectObject(hMemoryDC, hCaptureBitmap);
char str1[50] = "D:/123.bmp";
SaveBMPToFile(hCaptureBitmap, str1, pt.x, pt.y);
DeleteDC(hDesktopDC);
DeleteDC(hMemoryDC);
DeleteObject(hCaptureBitmap);
}基于Mirror Driver的屏幕捕捉技术
最新推荐文章于 2021-01-14 12:20:46 发布
本文介绍了如何使用C++在Windows环境下捕获屏幕截图,并在截图上绘制鼠标位置。通过创建内存DC、位图和使用BitBlt函数,实现屏幕截图的获取。进一步通过LoadCursor和DrawIconEx函数,动态显示鼠标图标。最后,使用SaveBMPToFile函数保存截图到指定文件。此过程涉及图形API和位图操作。
3580

被折叠的 条评论
为什么被折叠?



