Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Drawing a picture in a memory DC?

Posted on 2001-07-01
1
Medium Priority
?
469 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 400 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 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