One of the common questions that I find on the microsoft.public forums is "How do I get a bitmap of a window on the screen?" Well, here's a little subroutine I used extensively in writing Win32 Programming, because I realized that for the number of illustrations I wanted for the book, there was no hope of doing screen captures and then hand-editing just the control I wanted to show. So all my Explorers have a little button somewhere that performs a screen capture of the example window and drops it into the clipboard. I could then paste it into the document, or paste it into an editor and save it as a TIFF or JPEG as well.
void toClipboard(CWnd * wnd, BOOL FullWnd);
void toClipboard(CWnd * wnd, BOOL FullWnd)
HDC hdc = ::GetWindowDC(wnd->m_hWnd);
HDC hdc = ::GetDC(wnd->m_hWnd);
CSize sz(r.Width(), r.Height());
bm.CreateCompatibleBitmap(&dc, sz.cx, sz.cy);
CBitmap * oldbm = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, sz.cx, sz.cy, &dc, 0, 0, SRCCOPY);
The views expressed in these essays are those of the author, and in no way represent, nor are they endorsed by, Microsoft.