Solved

Drawing a picture in a memory DC?

Posted on 2001-07-01
1
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 146
Named range not carried over 10 71
ffmpeg - "rtsp://...... Operation not permitted" 4 92
firstChar challenge 13 149
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 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