C++ double buffer and memory
Ok so my double buffer works fine but it seems that it use a lot of memory.
i know that double buffer should store a copy of the ellipse I'm drawing than paint it on the screen but it after that it deletes the copy and makes new copy but it doesn't seem to delete it here is my code
hdc=GetDC(hWnd);
HDC memDC=CreateCompatibleDC(hdc);
HBITMAP hMemMap=CreateCompatibleBitmap(hdc, 300, 300);
HBITMAP hOldMap=(HBITMAP)SelectObject(memDC, hMemMap);
// Drawing
Graphics draw(memDC);
draw.FillRectangle(&green, 0, 0, 300, 25);
Font font(&fontfamily, 14, 0, UnitPixel);
PointF p1(180.0f, 4.0f);
PointF p2(30.0f, 4.0f);
draw.DrawString(level, -1, &font, p2, &blue);
draw.DrawString(str, -1, &font, p1, &blue);
draw.FillEllipse(&red, ball1.Ex, ball1.Ey, 25, 25);
draw.FillEllipse(&red, ball2.Ex, ball2.Ey, 25, 25);
draw.FillEllipse(&red, ball3.Ex, ball3.Ey, 25, 25);
draw.FillEllipse(&red, ball4.Ex, ball4.Ey, 25, 25);
draw.FillEllipse(&red, ball5.Ex, ball5.Ey, 25, 25);
draw.FillEllipse(&red, ball6.Ex, ball6.Ey, 25, 25);
draw.FillEllipse(&red, ball7.Ex, ball7.Ey, 25, 25);
draw.FillEllipse(&red, ball8.Ex, ball8.Ey, 25, 25);
draw.FillEllipse(&red, ball9.Ex, ball9.Ey, 25, 25);
draw.FillEllipse(&red, ball10开发者_如何学C.Ex, ball10.Ey, 25, 25);
BitBlt(hdc, 0, 0, 300, 300, memDC, 0, 0, SRCCOPY);
SelectObject(memDC, hOldMap);
DeleteObject(hMemMap);
DeleteDC(memDC);
Any ideas?
You are destroying all objects, but not the DC. You must call ReleaseDC after the drawing.
See the MSDN:
After painting with a common device context, the ReleaseDC function must be called to release the device context.
精彩评论