Click here to Skip to main content
Click here to Skip to main content

CBitmapDC - An automatic memory DC wrapper

, 24 Nov 1999
Rate this:
Please Sign up or sign in to vote.
A handy class that provides a memory bitmap device context
  • Download demo project - 18 Kb
  • Download source - 5 Kb
  • <!-- Article Starts -->

    CBitmapDC is a subclass of CDC. It is a handy little class that provides a memory bitmap device context without having to reinvent the wheel every time you need one.

    Example 1

    CBitmapDC can be used to make a CBitmap on the fly
    1. make a memory bitmap DC by calling CBitmapDC's constructor with the desired bitmap width and height
    2. draw in this device context with normal CDC drawing functions
    3. call CBitmapDC's Close function, this returns a pointer to the finished CBitmap
    4. do whatever you want to do with the CBitmap
    5. delete the CBitmap
    <!-- start a block of source code -->
    void CMyView::OnDraw(CDC* pDC)
    {
      CBitmapDC bitmapDC(50, 50, pDC);
      bitmapDC.Rectangle(0, 0, 50, 50);
      bitmapDC.MoveTo(0,50);
      bitmapDC.LineTo(50,0);
      CBitmap *pbmp = bitmapDC.Close();
      DrawBitmap(pbmp, pDC, CPoint(10, 10));
      delete pbmp;
    }
    

    Example 2

    CBitmapDC can be used as a temporary scratchpad
    1. make a memory bitmap DC by calling CBitmapDC's constructor with the desired bitmap width and height
    2. draw in this device context with normal CDC drawing functions
    3. do whatever you want to do e.g. blit the memory DC to screen
    4. use the automatic cleanup of CBitmapDC's destructor
    void CMyView::OnDraw(CDC* pDC)
    {
      CBitmapDC bitmapDC_2(50, 50, pDC);
      bitmapDC_2.Rectangle(0, 0, 50, 50);
      bitmapDC_2.MoveTo(0, 0);
      bitmapDC_2.LineTo(50, 50);
      pDC->BitBlt(200, 10, 50, 50, &bitmapDC_2, 0, 0, SRCCOPY);
    }
    

    License

    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

    Share

    About the Author

    Anneke Sicherer-Roetman
    Web Developer
    Netherlands Netherlands
    No Biography provided

    Comments and Discussions

     
    GeneralLicensing PinmemberAnnaPe18-Apr-11 5:26 
    Hello!
     
    Do you have any useage terms or license associated with CBitmapDC? I'm interested in using this in my work, but I need to check with the legal team first to see if it's OK to use. Is it free to use and distribute with commercial products?
     
    Thanks for your help!
    Anna
    QuestionHow to display a bitmap image into a dialog in vc++/mfc PinsussAnonymous3-Apr-05 0:49 
    GeneralPrinting PinmemberGavriloaie Andrei11-Nov-04 8:25 
    Questionhow to load Bitmap after a image manipulation? Pinmembergilazilla18-Aug-04 5:47 
    Generalthanks very much Pinmemberphilipcunningham12-Apr-04 3:16 
    GeneralWindows CE PinmemberJoão Paulo Figueira11-Sep-03 3:53 
    GeneralCBITMAPDC PinmemberMaverick1-Jan-02 5:00 
    GeneralSame thing using CMemDC... PinmemberAnonymous19-Aug-01 23:14 
    QuestionHow can i do it PinsussYoo28-Sep-00 18:27 
    AnswerRe: How can i do it PinmemberAnneke Sicherer-Roetman29-Sep-00 0:52 
    GeneralRe: How can i do it - bugfix PinsussAnonymous27-May-03 10:25 
    GeneralRe: How can i do it - bugfix PinmemberAnneke Sicherer-Roetman27-May-03 21:57 
    GeneralRe: How can i do it - bugfix PinmemberBarryHolleran17-Feb-04 5:56 
    GeneralRe: How can i do it - bugfix PinmemberBarryHolleran17-Feb-04 6:01 
    GeneralRe: How can i do it - bugfix PinmemberWolfgang Kleinschmit6-Apr-04 0:21 
    GeneralRe: How can i do it PinmemberJHAKAS17-Apr-04 21:50 

    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 | Terms of Use | Mobile
    Web04 | 2.8.141223.1 | Last Updated 25 Nov 1999
    Article Copyright 1999 by Anneke Sicherer-Roetman
    Everything else Copyright © CodeProject, 1999-2014
    Layout: fixed | fluid