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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| void CMyListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if(bIHMEnfant)
{
CDC* pdc;
pdc=new CDC();
pdc->Attach(lpDrawItemStruct->hDC);
// Load BITMAP from the file.
CBitmap *bmp;
for(int i=1; i<5;i++)
{
HBITMAP hBitmap = (HBITMAP)LoadImage( 0,TabBitmapName[i][0],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);
// Create an in-memory device context compatible with the
// display device context that is used to paint.
CDC dcMemory;
dcMemory.CreateCompatibleDC(pdc);
// Select the bitmap into the in-memory device context.
CBitmap* pOldBitmap = dcMemory.SelectObject(bmp);
// Find a center point for the bitmap in the client area.
CRect rect;
GetClientRect(&rect);
int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;
// 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);
}//end for
}else
{
ASSERT(lpDrawItemStruct->CtlType == ODT_LISTBOX);
LPCTSTR lpszText=NULL ;
CString str;
// si le style est different de LBS_HASSTRINGS on considère que la valeur à afficher
//est dans ItemData.
if(lpDrawItemStruct->itemID!=CB_ERR && !(GetStyle() & LBS_HASSTRINGS))
lpszText=(LPCTSTR) lpDrawItemStruct->itemData;
else
{
// Récupération de la chaîne grâce à l'index stocké dans ItemID.
GetText(lpDrawItemStruct->itemID,str);
lpszText= str;
}
ASSERT(lpszText != NULL);
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
//si item selectionné
if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED) )
{
if(m_bBlink && m_bFlipFlap)//clignotement?
{
dc.SetTextColor(crTextColor);
dc.FillSolidRect(&lpDrawItemStruct->rcItem,crBkColor);
}else
{
dc.SetTextColor(crBkColor);
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crTextColor);
}
}
else //si item non selectionné
{
dc.SetTextColor(crTextColor);
dc.FillSolidRect(&lpDrawItemStruct->rcItem,crBkColor);
}
// If this item has the focus, draw a red frame around the
// item's rect.
/* if ((lpDrawItemStruct->itemAction | ODA_FOCUS) &&
(lpDrawItemStruct->itemState & ODS_FOCUS))
{
CBrush br(RGB(255, 0, 0));
dc.FrameRect(&lpDrawItemStruct->rcItem, &br);
}*/
// Draw the text.
dc.DrawText(lpszText,
strlen(lpszText),
&lpDrawItemStruct->rcItem,
DT_CENTER|DT_SINGLELINE|DT_VCENTER);
// Reset the background color and the text color back to their
// original values.
//dc.SetTextColor(crOldTextColor);
//dc.SetBkColor(crOldBkColor);
dc.Detach();
}//end if(bIHMEnfant)
} |
Partager