问题描述
我尝试使用gdi捕获某些窗口,大多数窗口都可以。 但是对于诸如“ Visual Studio代码”之类的窗口,它不起作用。 DX不支持捕获特定窗口。 我应该怎么做?谢谢
::EnumWindows(EnumWindowsProc,NULL);
if (hCapWnd == NULL)
{
return FALSE;
}
SwitchToThisWindow(hCapWnd,true);
Sleep(1000);
//HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetWindowDC(hCapWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
SetStretchBltMode(hCaptureDC,COLORONCOLOR);
RECT rc;
::GetWindowRect(hCapWnd,&rc);
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC,width,height);
SelectObject(hCaptureDC,hCaptureBitmap);
BOOL bRet = BitBlt(hCaptureDC,height,hDesktopDC,SRCCOPY);
Init(width,height);
int nRet = GetDIBits(hCaptureDC,hCaptureBitmap,buf,(BITMAPINFO*)&m_bitmapInfo,DIB_RGB_COLORS);
static int n = 0;
//if (n++ % 10 == 0)
{
// std::string name = ustd::format_string("%s\\%d.bmp",ustd::get_program_path().c_str(),n);
SaveBitmapToFile(hCaptureBitmap);
}
ReleaseDC(hCapWnd,hDesktopDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitmap);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)