?
Solved

Temp DC

Posted on 2003-03-05
7
Medium Priority
?
264 Views
Last Modified: 2013-11-20
I have a program with SDI document and i'm drawing all kinds of things on the client area. What i did was to call Draw functions of all object that should be drawn from the View class Draw function.

My problem is that it draws everything slowly. What i tried was to create a temp CDC object and send it to the draw functions and when it returns copy it to the active DC. I tried using BitBlt but it doesnt work. How can i do this?
0
Comment
Question by:Yevgen
[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
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:KurtVon
ID: 8073180
You may need to call CreateCompatableBitmap on the DC, then select the bitmap into the DC.  If you just create a DC it has a monochrome one pixel bitmap by default.

If that isn't the problem you really will need to provide a code sample or more details.
0
 

Author Comment

by:Yevgen
ID: 8073692
Can you show me how to do this. I need the temp DC to be the same size as the main DC.

Tnx...
0
 
LVL 11

Accepted Solution

by:
KurtVon earned 400 total points
ID: 8074021
CDC dcMem;
CBitmap bmMem;
CRect rcClient;

GetClientRect(rcClient);

dcMem.CreateCompatibleDC(&paintDC);
bmMem.CreateCompatibleBitmap(&dcMem, rcClient.Width(), rcClient.Height());
CObject* pbmOld = dcMem.SelectObject(&bmMem);

// Do drawing stuff

paintDC->BitBlt(0, 0, rcClient.Width(), rcClient.Height(), &dcMem, 0, 0, SRCCOPY);

dcMem.SelectObject(pbmOld);


Nothing fancy to it.  This was entered by hand, so look out for typos.

0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:Yevgen
ID: 8075967
That works but the bitmap is monochrome and the background is black. Can you help me with this one?
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8076051
Whoops.

Change the &dcMem in the CreateCompatibleBitmap to &paintDC.

Like I said, the default bitmap is monochrome.
0
 

Author Comment

by:Yevgen
ID: 8078484
Tnx, one last thing... The pixels which i dont use are filled with random colors, can i somehow clean them?
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 8080240
Before drawing do a PatBlt with WHITENESS, or, to be more compatible, do a FillRect with a brush the color of the window:

CBrush brBackground(::GetSysColor(COLOR_WINDOW));
dcMem.FillRect(rcClient, brBackground); // rcClient always has (0, 0) as upper left.

Oh, and since you don't need it, override OnEraseBkgnd and just return TRUE so the system doesn't bother filling the window for you.

0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

752 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