Click here to Skip to main content
Click here to Skip to main content
Go to top

Screen Capture to the Clipboard

, 5 Apr 2001
Rate this:
Please Sign up or sign in to vote.
How do you capture the bitmap of a window? This little download shows how, and places the bitmap on the clipboard.


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);


#include "stdafx.h"
#include "toclip.h" 
*                                 toClipboard
* Inputs:
*       CWnd * wnd: Window whose contents are to be sent 
*                   to the clipboard
*       BOOL FullWnd: TRUE for entire window, 
*                     FALSE for client area
* Result: void
* Effect: 
*       Copies the contents of the client area or the window
*       to the clipboard in CF_BITMAP format.

void toClipboard(CWnd * wnd, BOOL FullWnd)
     CDC dc;
        { /* full window */
         HDC hdc = ::GetWindowDC(wnd->m_hWnd);
        } /* full window */
        { /* client area only */
         HDC hdc = ::GetDC(wnd->m_hWnd);
        } /* client area only */

     CDC memDC;

     CBitmap bm;
     CRect r;

     CString s;
     CSize sz(r.Width(), r.Height());
     CBitmap * oldbm = memDC.SelectObject(&bm);
     memDC.BitBlt(0, 0,,, &dc, 0, 0, SRCCOPY);

     ::SetClipboardData(CF_BITMAP, bm.m_hObject);

     bm.Detach();  // make sure bitmap not deleted with CBitmap object

The views expressed in these essays are those of the author, and in no way represent, nor are they endorsed by, Microsoft.

Send mail to with questions or comments about this article.
Copyright © 1999 All Rights Reserved


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Joseph M. Newcomer

United States United States
No Biography provided

Comments and Discussions

GeneralRe: how to save clipboard to file?? PinmemberJoseph M. Newcomer14-Jan-04 8:58 
AnswerRe: how to save clipboard to file?? PinmemberNeWi13-Oct-05 7:18 
QuestionHow to convert to non-mfc? PinmemberTommy2k9-Dec-03 11:22 
AnswerRe: How to convert to non-mfc? PinmemberNeWi13-Oct-05 7:25 
QuestionHow can i detect a global screen capture? PinmemberMiguel Lopes27-Oct-03 13:38 
AnswerRe: How can i detect a global screen capture? PinmemberJoseph M. Newcomer2-Nov-03 13:29 
QuestionHow can I print it? PinmemberAlex Evans30-Sep-03 14:32 
GeneralCapturing the whole window PinsussArne Diegenbach25-Sep-03 11:35 
// Insert the following to capture the whole window
// as long as it fits on the screen
// display is of type CWnd* (or derived from)
CWnd * savedParent = display->GetParent();
CRect r;
display->ModifyStyleEx(0, WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
// this might be a good place to force the with or height of the window bounds r
display->MoveWindow(10, 10, r.Width(), r.Height());
// restore parent window
// restore style without moving it
display->ModifyStyleEx( WS_EX_TOOLWINDOW | WS_EX_TOPMOST, 0,
// restore window position

GeneralI rate 5 for this article! Pinmemberxxxyyyzzz12-Feb-03 10:17 
Generalsomething that you don't need PinsussAnonymous10-Oct-02 3:44 
GeneralRe: something that you don't need PinmemberJoseph M. Newcomer10-Oct-02 15:23 
Generalthere's a bug Pinsusspangtao17-Jul-02 17:45 
GeneralPossible Resource Leakage PinmemberLim Bio Liong7-Jan-02 22:27 
GeneralRe: Possible Resource Leakage PinmemberDoug Hagerman1-Mar-02 15:49 
GeneralRe: Possible Resource Leakage PinmemberLim Bio Liong1-Mar-02 17:19 
GeneralRe: Possible Resource Leakage PinmemberJoseph M. Newcomer1-Mar-02 20:10 
GeneralRe: Possible Resource Leakage PinmemberJoseph M. Newcomer1-Mar-02 20:03 
GeneralRe: Possible Resource Leakage PinmemberLim Bio Liong2-Mar-02 23:39 
QuestionAn easier way? PinmemberLrdElder6-Jan-02 9:25 
QuestionHow To Capture Mouse Pointer Image Also PinmemberSujeet1-Nov-01 21:41 
AnswerRe: How To Capture Mouse Pointer Image Also PinmemberJoseph M. Newcomer4-Nov-01 6:12 
AnswerRe: How To Capture Mouse Pointer Image Also PinmemberJoseph M. Newcomer4-Nov-01 6:16 
GeneralRe: How To Capture Mouse Pointer Image Also PinmemberKunjan Shah26-Nov-01 21:49 
QuestionHow to capture mediaplayer window ? PinmemberAnonymous4-Sep-01 5:02 
QuestionHow to receive list of Working applications with their windows' handles? PinmemberSash22-Jun-01 23:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 6 Apr 2001
Article Copyright 2001 by Joseph M. Newcomer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid