Solved

Drawing a picture in a memory DC?

Posted on 2001-07-01
1
418 Views
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)
{
MemoryDC.CreateCompatibleDC(pcdc);
Picture.Render(MemoryDC, crcBounds, crcBounds);
}

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

Accepted Solution

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

{
CDC memoryDC;
memoryDC.CreateCompatibleDC(pcdc);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(pcdc,nWidth,nHeight);
CBitmap *oldb=memoryDC.SelectObject(&bitmap);

// now you can work on your memoryDC


pcdc->BitBlt(0,0,nWidth,nHeight,0,0,SRCAND);
memoryDC.SelectObject(oldb);
}

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now