1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| void CMyListBox::ImageDraw(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC *pdc;
pdc=new CDC();
CBitmap *bmp;
CString str;
GetText(lpDrawItemStruct->itemID,str);
HBITMAP hBitmap=(HBITMAP)LoadImage( 0,str,IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_LOADMAP3DCOLORS|LR_SHARED );
bmp = CBitmap::FromHandle(hBitmap);
// Get the size of the bitmap.
BITMAP bmpInfo;
bmp->GetBitmap(&bmpInfo);
pdc->Attach(lpDrawItemStruct->hDC);
// Create an in-memory device context compatible with the
// display device context that is used to paint.
CDC dcMemory;
dcMemory.CreateCompatibleDC(pdc);
//si item selectionné
if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED) )
{
if(m_bBlink && m_bFlipFlap)//clignotement?
{
pdc->FillSolidRect(&lpDrawItemStruct->rcItem,crBkColor);
}else
{
pdc->FillSolidRect(&lpDrawItemStruct->rcItem, crTextColor);
}
}
else //si item non selectionné
{
pdc->FillSolidRect(&lpDrawItemStruct->rcItem,crBkColor);
}
// Select the bitmap into the in-memory device context.
CBitmap* pOldBitmap = dcMemory.SelectObject(bmp);
// affichage du bmp à l'emplacement voulu
//GetClientRect(&(lpDrawItemStruct->rcItem));
int nX = lpDrawItemStruct->rcItem.left + bmpInfo.bmWidth;
int nY = lpDrawItemStruct->rcItem.top;
// Copy the bits from the in-memory device context to the on-
// screen device context to do the painting. Use the computed center
// point for the target offset.
pdc->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
} |
Partager