I use acdbGetPreviewBitmapFromDwg to get a dwg file's preview bitmap and draw the bitmap on Image Listbox Control ,
but Listbox Control keeps in with executing Onpaint when scrolling, I found the storage is not recyled. here is my code and I
have executed DeleteObject(hBitmap), DeleteObject(hPalette);
Can you help to solve the problem!
HBITMAP hBitmap = NULL;
HPALETTE hPalette = NULL;
acdbGetPreviewBitmapFromDwg(item.szFilename, &hBitmap, &hPalette);
if(hBitmap!=NULL && hPalette!=NULL)
{
CPalette* oldPal = pDC->SelectPalette(CPalette::FromHandle(hPalette), TRUE);
pDC->RealizePalette();
CBitmap bitmap;
bitmap.Attach(hBitmap);
BITMAP bm;
bitmap.GetObject(sizeof(bm), (LPVOID)&bm);
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
CBitmap *pOldBitmap = dcMem.SelectObject(&bitmap);
//pDC->StretchBlt(rectTemp.left, rectTemp.top, (int)(bm.bmWidth*ds),(int)(bm.bmHeight*ds), &dcMem, 0, 0,bm.bmWidth, bm.bmHeight,SRCCOPY);
dcMem.SelectObject(pOldBitmap);
pDC->SelectPalette(oldPal,TRUE );
pDC->RealizePalette();
bitmap.DeleteObject();
DeleteObject(hBitmap);
DeleteObject(hPalette);
}