// Copy the lpsrcrect of the window pointed to by pwnd to the clipboard // run this program, you can open the drawing and paste the test copyscreentoclipboard (cwnd * pwnd, crect * lpsrcrect) {If (! Iswindow (pwnd-> getsafehwnd () {afxmessagebox ("Invalid Window handle"); Return (false);} // first, determine the update region and select ITIF (! Pwnd-> openclipboard () {afxmessagebox ("Clipboard cannot be opened"); Return (false) ;}// remove the current clipboard contentsif (! Emptyclipboard () {afxmessagebox ("failed to clear the Clipboard"); Return (false);} // int width = lpsrcrect-> width (); int Height = lpsrcrect-> height (); CDC * PDC = pwnd-> getdc (); // create a memory dccdc memdc; memdc. createcompatibledc (PDC); // create the bitmap cbitmap m_bitmap; m_bitmap.createcompatiblebitmap (PDC, width, height); // select the bitmap memdc. selectObject (& m_bitmap); // copy memdc. bitblt (0, 0, width, height, PDC, 0, 0, srccopy); // copy to the clipboard setclipboarddata (cf_bitmap, m_bitmap.m_hobject); // close the clipboard closeclipboard (); return (true );}