In programming windows chapter 14 blow-upProgramAfter the screen capture is completed, the author uses the followingCodeCopy the Screen Content in place:
HDC = getdc (_ hwnd); HDC hdcmem = createcompatibledc (HDC); hbitmap = createcompatiblebitmap (HDC, ABS (ptend. x-ptBeg.x), ABS (ptend. y-ptBeg.y); SelectObject (hdcmem, hbitmap); stretchblt (hdcmem, 0, 0, ABS (ptend. x-ptBeg.x), ABS (ptend. y-ptBeg.y), HDC, ptbeg. x, ptbeg. y, ptend. x-ptBeg.x, ptend. y-ptBeg.y, srccopy); deletedc (hdcmem); releasedc (_ hwnd, HDC );
Test in my own Win7-32bit is not able to copy the content correctly, because getdc (_ hwnd) is just getting the DC of the customer zone and cannot get the data outside the customer zone, the effect is as follows:
After the content is copied:
to correctly copy the captured screen content, we need to obtain the screen DC and use the screen coordinates for operations. The Code is as follows:
Point ptscreenbeg = ptbeg; point ptscreenend = ptend; clienttoscreen (_ hwnd, & ptscreenbeg); clienttoscreen (_ hwnd, & ptscreenend); HDC = getdcex (hwnddesktop, null, dcx_cache | dcx_lockwindowupdate); HDC hdcmem = createcompatibledc (HDC); hbitmap = createcompatiblebitmap (HDC, ABS (ptscreenend. x-ptScreenBeg.x), ABS (ptscreenend. y-ptScreenBeg.y); SelectObject (hdcmem, hbitmap); stretchblt (hdcmem, 0, 0, ABS (ptscreenend. x-ptScreenBeg.x), ABS (ptscreenend. y-ptScreenBeg.y), HDC, ptscreenbeg. x, ptscreenbeg. y, ptscreenend. x-ptScreenBeg.x, ptscreenend. y-ptScreenBeg.y, srccopy); deletedc (hdcmem); releasedc (hwnddesktop, HDC );
In this way, we can copy the captured screen content to the bitmap as follows:
After the content is copied: