I have a little modified QScreen::grabWindow function. And on some computers, unfortunately I didn't find relationship between them, BitBlt freezes for even minutes! Why this can happen and what can I do?
QPixmap DetectionFlow::grabScreen(HWND h)
{
RECT rect;
GetClientRect(h, (LPRECT)&rect);
// get the height and width of the screen
int height = rect.bottom - rect.top;
int width = rect.right - rect.left;
// Create and setup bitmap
HDC display_dc = GetDC(0);
HDC bitmap_dc = CreateCompatibleDC(display_dc);
HBITMAP bitmap = CreateCompatibleBitmap(display_dc, width, height);
HGDIOBJ null_bitmap = SelectObject(bitmap_dc, bitmap);
HDC window_dc = GetDC(h);
BitBlt(bitmap_dc, 0, 0, width, height, window_dc, 0, 0, SRCCOPY);
// clean up all but bitmap
ReleaseDC(h, window_dc);
SelectObject(bitmap_dc, null_bitmap);
DeleteDC(bitmap_dc);
const QPixmap pixmap = qt_pixmapFromWinHBITMAP(bitmap);
DeleteObject(bitmap);
ReleaseDC(0, display_dc);
return pixmap;
}
PS. What is interesting, on computers, where freezes, it freezes randomly. So usually there it works fast (a couple of ms) and then freeze.
Problem was in Aero. Computers that freezes with BitBlt has Win7 and Aero. Without Aero all ok.