Solved

Drawing a picture in a memory DC?

Posted on 2001-07-01
1
439 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 158
withoutTen challenge 14 120
canBalance challenge 34 81
Fibonacci challenge 11 121
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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