Programming windows-Chapter 14 blow-up program error

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.