I am currently working on an ActiveX control, which shall write strings on the screen. Every letter is represented by a CBitmap (about 10*12 px * 16 colours) object. Every letter is a member-variable (CBitmap letterA, letterB...)and is initialized in the constructor (LoadBitmap(ID)). Then all the labels on the control have their own buffer dc (also as members initialized in the constructor).Actually everything works fine, except a memory leak every time this loop is called (toWrite is a CString object):
CDC* buffer= &m_dcFirstLabel;//or &m_dcSecondLabel etc.
for(int i=0; i<toWrite.GetLength(); i++)
{
CBitmap* bmp= &letterA;//no wild pointers!
switch(toWrite.GetAt(i))
{
case 'A':{bmp= &letterA;};break;
case 'B':{bmp= &letterB;};break;
case 'C':{bmp= &letterC;};break;
case 'D':{bmp= &letterD;};break;
//all other letters
}
CDC bmpDC;
bmpDC.CreateCompatibleDC(GetDC());
CBitmap* old= bmpDC.SelectObject(bmp);
buffer->BitBlt(posToWrite, 0,bmp-> GetBitmapDimension().cx, bmp->GetBitmapDimension().cy, &bmpDC, 0, 0, SRCCOPY);
posToWrite+=bmp->GetBitmapDimension().cx;
bmpDC.SelectObject(old);
bmpDC.DeleteDC();
}//for end
Could anyone give me a hint, were the leak could be, cause I loose about 4KB every time I call this function with a string of 5 characters.
CDC* buffer= &m_dcFirstLabel;//or &m_dcSecondLabel etc.
for(int i=0; i<toWrite.GetLength(); i++)
{
CBitmap* bmp= &letterA;//no wild pointers!
switch(toWrite.GetAt(i))
{
case 'A':{bmp= &letterA;};break;
case 'B':{bmp= &letterB;};break;
case 'C':{bmp= &letterC;};break;
case 'D':{bmp= &letterD;};break;
//all other letters
}
CDC bmpDC;
bmpDC.CreateCompatibleDC(GetDC());
CBitmap* old= bmpDC.SelectObject(bmp);
buffer->BitBlt(posToWrite, 0,bmp-> GetBitmapDimension().cx, bmp->GetBitmapDimension().cy, &bmpDC, 0, 0, SRCCOPY);
posToWrite+=bmp->GetBitmapDimension().cx;
bmpDC.SelectObject(old);
bmpDC.DeleteDC();
}//for end
Could anyone give me a hint, were the leak could be, cause I loose about 4KB every time I call this function with a string of 5 characters.