Screenshot interface: QWindowsScreen: : grabWindow
Specific internal implementation:
QPixmap QWindowsScreen: : grabWindow (WId window, int x, int y, int width, int height) const
{
The RECT r;
HWND HWND=window? Reinterpret_cast & lt; HWND> (Windows) : GetDesktopWindow ();
GetClientRect (HWND, & amp; R);
If (width & lt; Width=0) r.r d.light - r.l eft;
If (height & lt; Height=0) r. b ottom - r.t op;
//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);
//copy data
HDC window_dc=GetDC (HWND);
BitBlt (bitmap_dc, 0, 0, width, height, window_dc, x, y, SRCCOPY | CAPTUREBLT);
//clean up all but bitmap
ReleaseDC (HWND, window_dc);
SelectObject (bitmap_dc null_bitmap);
DeleteDC (bitmap_dc);
Const QPixmap pixmap=qt_pixmapFromWinHBITMAP (bitmap);
DeleteObject (bitmap);
ReleaseDC (0, display_dc);
Return the pixmap;
}
Current analysis: aero theme appearance, basic pay attention to system run speed, aero effect is better, in terms of rendering the above code//copy data
HDC window_dc=GetDC (HWND);
BitBlt (bitmap_dc, 0, 0, width, height, window_dc, x, y, SRCCOPY | CAPTUREBLT);
If in front of the code to add Sleep (100) capture program the main window of residual problems will reduce very much, but still a probability, does somebody know a concrete reason, have what scheme can hedge, reference the competing goods WeChat and nailing is not the problem,
CodePudding user response:
The HDC window_dc=GetDC (HWND);BitBlt (bitmap_dc, 0, 0, width, height, window_dc, x, y, SRCCOPY | CAPTUREBLT);
//clean up all but bitmap
ReleaseDC (HWND, window_dc); This paragraph
With the PrintWindow try, may be the window hasn't refresh