我试图用SendMessage和wm_paint和wm_printclient来捕捉游戏窗口。
我已经成功地使用了PrintWindow,但是游戏可以改变图形引擎之间的变化,对于其中一些引擎,我会得到一个白色的矩形。我希望使用SendMessage不会出现这个问题。
问题是,由于SendMessage,任何图形引擎,甚至任何程序/窗口,我都会得到一个黑色的矩形。
void capture::captureProgramScreen(HWND hwnd, tImage* res)
{
RECT rc;
GetWindowRect(hwnd, &rc);
//create
HDC hdcScreen = GetDC(NULL);
HDC hdc = CreateCompatibleDC(hdcScreen);
HBITMAP hbmp = CreateCompatibleBitmap(hdcScreen, rc.right - rc.left, rc.bottom - rc.top);
res->width = rc.right - rc.left - 17;
res->height = rc.bottom - rc.top - 39;
res->absoluteTop = rc.top;
res->absoluteLeft = rc.left;
SelectObject(hdc, hbmp);
SendMessage(hwnd, WM_PRINTCLIENT, (int)hdc, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);
BITMAPINFO MyBMInfo = { 0 };
MyBMInfo.bmiHeader.biSize = sizeof(MyBMInfo.bmiHeader);
if (0 == GetDIBits(hdc, hbmp, 0, 0, NULL, &MyBMInfo, DIB_RGB_COLORS))
{
res->error = true;
res->errorcode = 2;
return;
}
res->v = std::vector<BYTE>(MyBMInfo.bmiHeader.biSizeImage);
MyBMInfo.bmiHeader.biBitCount = 32;
MyBMInfo.bmiHeader.biCompression = BI_RGB;
MyBMInfo.bmiHeader.biHeight = abs(MyBMInfo.bmiHeader.biHeight);
if (0 == GetDIBits(hdc, hbmp, 0, MyBMInfo.bmiHeader.biHeight, &(res->v[0]), &MyBMInfo, DIB_RGB_COLORS))
{
res->error = true;
res->errorcode = 3;
res->width = 0;
res->height = 0;
res->v.clear();
return;
}
//4 Bytes per pixel order (B G R A) from [left to right] [bottom to top]
return;
}谢谢!
发布于 2016-12-31 17:41:30
至少有几个可能的问题:
WM_PRINTCLIENT。许多游戏甚至没有实现WM_PAINT,因为它们不断地以自己想要的帧速率绘制,而不是响应更新自己的需要。许多游戏使用新的图形API,这些API并没有真正吸引到设备上下文。https://stackoverflow.com/questions/41409563
复制相似问题