• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Temp DC

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
Yevgen
Asked:
Yevgen
  • 4
  • 3
1 Solution
 
KurtVonCommented:
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
 
YevgenAuthor Commented:
Can you show me how to do this. I need the temp DC to be the same size as the main DC.

Tnx...
0
 
KurtVonCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
YevgenAuthor Commented:
That works but the bitmap is monochrome and the background is black. Can you help me with this one?
0
 
KurtVonCommented:
Whoops.

Change the &dcMem in the CreateCompatibleBitmap to &paintDC.

Like I said, the default bitmap is monochrome.
0
 
YevgenAuthor Commented:
Tnx, one last thing... The pixels which i dont use are filled with random colors, can i somehow clean them?
0
 
KurtVonCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now