Drawing a picture in a memory DC?

Posted on 2001-07-01
Medium Priority
Last Modified: 2013-11-20
I have a picture in a CPictureHolder, I need to render this picture in a memory DC then use the memory DC in a  BitBlt function to draw parts of it on the screen.
I wrote some code but it is not working, what did I miss or is it not a valid idea?

void CControl::OnDraw(CDC* pcdc, const CRect& crcBounds, const CRect& crcInvalid)
Picture.Render(MemoryDC, crcBounds, crcBounds);

cdc->BitBlt(0, 0, nWidth, nHeight, &MemoryDC, 0, 0, SRCAND);
Question by:Daed
1 Comment

Accepted Solution

gilad_no earned 400 total points
ID: 6242527
You need to create and attach a bitmap to the memory dc before you use it.

CDC memoryDC;
CBitmap bitmap;
CBitmap *oldb=memoryDC.SelectObject(&bitmap);

// now you can work on your memoryDC


Since you create the memoryDC in the stack, you don't need to destroy it by yourself

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question