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
|
m_liste.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL|LVS_OWNERDRAWFIXED,CRect(5,5,200,200),this,123);
m_liste.InsertItem(0,"toto1");
m_liste.InsertItem(1,"toto1");
m_liste.InsertItem(2,"toto2");
m_liste.InsertItem(3,"toto3");
m_liste.InsertItem(4,"toto4");
m_liste.InsertItem(5,"toto5");
m_liste.InsertItem(6,"toto6");
m_liste.InsertItem(7,"toto7");
m_liste.InsertItem(8,"toto8");
m_liste.ShowWindow(SW_SHOW);
et voici le code de ma liste (je ne passes toujours pas dans DrawItem) :
BEGIN_MESSAGE_MAP(ClistColor, CListCtrl)
//{{AFX_MSG_MAP(CListCtrl)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_WM_DRAWITEM_REFLECT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ClistColor diagnostics
/////////////////////////////////////////////////////////////////////////////
// ClistColor message handlers
void ClistColor::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// Recup du CDC ............................................................
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
// Recup de l'item .........................................................
int nItem = lpDrawItemStruct->itemID;
BOOL bFocus = (GetFocus() == this);
// Recup du rectangle de dessin de l'item ..................................
CRect rcItem(lpDrawItemStruct->rcItem);
CRect rcAllLabels;
GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);
// Test Rang paire / impaire ...............................................
if (nItem > -1)
{
if ((nItem % 2) == 0)
{
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(247,185,255));
pDC->FillRect(rcAllLabels, &CBrush(RGB(247,185,255)));
}
else
{
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(255,255,255));
pDC->FillRect(rcAllLabels, &CBrush(RGB(255,255,255)));
}
}
} |
Partager