Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ WinAPI PrintWindow()的更快替代方案?_C++_Windows_Winapi_Screenshot - Fatal编程技术网

C++ WinAPI PrintWindow()的更快替代方案?

C++ WinAPI PrintWindow()的更快替代方案?,c++,windows,winapi,screenshot,C++,Windows,Winapi,Screenshot,我正在编写一个程序,它连续扫描打开窗口(可能在背景中)的一些像素,并对更改做出反应。我目前正在使用以下代码: HDC ClientProfile::prepareSurface() { UpdateWindow(handle); HDC window_dc = GetDC(handle); HDC res = CreateCompatibleDC(window_dc); RECT r; GetClientRect(handle, &r);

我正在编写一个程序,它连续扫描打开窗口(可能在背景中)的一些像素,并对更改做出反应。我目前正在使用以下代码:

HDC ClientProfile::prepareSurface() {
    UpdateWindow(handle);
    HDC window_dc = GetDC(handle);
    HDC res = CreateCompatibleDC(window_dc);
    RECT r;
    GetClientRect(handle, &r);
    HBITMAP bmp = CreateCompatibleBitmap(window_dc, r.right - r.left, r.bottom - r.top);
    SelectObject(res, bmp);
    PrintWindow(handle, res, PW_CLIENTONLY);
    DeleteObject(bmp);
    ReleaseDC(handle, window_dc);
    return res;
}
然后在返回的HDC上使用GetPixel()。这绝对可以,但是当同时扫描很多窗口时,它对我的需要来说有点太慢了。 我特别注意到PrintWindow()使用的时间因其扫描的应用程序而异(可能是因为消息的处理方式)。 有没有办法加快速度?我试着用

SendMessage(handle,WM_PRINT/WM_PRINTCLIENT, WPARAM(res),PRF_CLIENT);
但这根本不起作用(这会有什么不同吗?)。 我找不到任何其他解决我问题的方法,这附近有人有可能有吗


提前感谢。

您确定它的打印窗口是一个瓶颈吗?GetPixel可能也很耗时——特别是如果在DC上执行,可能会将其缓冲区保留在视频内存中。我只检查单个像素,每次迭代只检查几个像素。我用“英特尔VTUNE放大器”检查了该程序,结果如下。有趣的是:我用windows PerformanceQueryCounter检查了“PrintWindow()”函数所用的时间。它大部分时间返回1.000微秒,但每隔一段时间(比如每秒一次),它需要大约20000微秒。为什么会这样?