Resource leak in my application...
Posted on 2001-08-30
hi... I am having this problem... I am working on a tetris game, very simple.
But when I draw the blocks to the screen, I want to draw everything to a
temporary CDC first and then copy this CDC to the window DC, so I don't have
any flickering. I have worked on some code, and it works fine under windows
2000, but under windows 95/98/ME I end up running out of resources. I am
sure I am doing something wrong, I just can't figure that out. The code that
I have is....
CDC * dc;
CBitmap * pOldBmp;
CBrush * pOldBrush;
// Create the brush
dc = this->GetDC();
// Get the client are size
// Create the dc and prepare to copy
pOldBmp = memdc.SelectObject(&membmp);
// Screen proportion
blockSize = (int) (20 * ScreenRatio);
centerPoint = clientRect.CenterPoint().x - (100*ScreenRatio);
// Clear the background
pOldBrush = memdc.SelectObject(&blackBrush);
//pOldBrush = dc->SelectObject(&blackBrush);
dc->StretchBlt(centerPoint,20,(int) (200*ScreenRatio),(int) (400*ScreenRatio),&memdc,0,0,200,400,SRCCOPY);
DrawScoreWindow(centerPoint + (200*ScreenRatio) + 20, 20);
I also posted the first way I did it, commented out, which is writing everything
straight to the window dc. It works fine under all windows, but the flickering
is so annoying that no one can stand it. I would really appreciate some feedback
on this. Thank you...