Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing shapes and lines

Status
Not open for further replies.

qedusa

Programmer
Joined
Jan 12, 2002
Messages
43
Location
US
Hi, I can draw the shapes and lines, etc OK but I want to know if there's a way I can draw these offscreen and then copy them instantaneously to the screen so the drawing process appears smooth and instant just like drawing a bitmap using BitBlt() function.

As an example, say I want to draw a graph or pie chart and want to update it every so often. I would like the updated graph to appear instant rather then the user seeing the entire graph being built up from scratch again every time.

Is there a way I can do this and, if so, how?

Thanks
 
...just like drawing a bitmap using BitBlt() function.

That's the way!
Here's an example. It's quite simple, I guess there's no need to further explanations.

CClientDC clientDC(this);
CDC memDC;
CBitmap memBitmap;
CRect rect;

memDC.CreateCompatibleDC(&clientDC);
GetClientRect(&rect);
memBitmap.CreateCompatibleBitmap(&clientDC,rect.Width(),rect.Height());
memDC.SelectObject(&memBitmap);

// Here goes your drawing code
for (int i=0; i<rect.Width(); i++) {
for (int j=0; j<rect.Height(); j++) {
memDC.SetPixel(i,j,RGB(i%255,j%255,(i*j)%255));
}
}
// end drawing code

clientDC.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);


I hope this is what you were looking for.
 
Thanks!! I'll give it a blast!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top