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 105 106 107 108 109 110 111 112 113 114
|
/////////////////////////////////////////////////////////////////////////////
// CListCtrlEx
CListCtrlEx::CListCtrlEx()
{
}
CListCtrlEx::~CListCtrlEx()
{
}
BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
//{{AFX_MSG_MAP(CListCtrlEx)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListCtrlEx message handlers
void CListCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
if(lpDrawItemStruct == NULL) return;
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
int nSavedDC = pDC->SaveDC();
RECT r;
CRect rItem( lpDrawItemStruct->rcItem );
CBrush* pBrush;
r.left = lpDrawItemStruct->rcItem.left;
r.right = lpDrawItemStruct->rcItem.right;
r.top = lpDrawItemStruct->rcItem.top;
r.bottom = lpDrawItemStruct->rcItem.bottom;
CRect rect(r);
int nItem = lpDrawItemStruct->itemID;
BOOL bsel =
(
(/*(lpDrawItemStruct->itemAction & ODA_FOCUS) &&*/ (lpDrawItemStruct->itemState & ODS_FOCUS)) ||
( (lpDrawItemStruct->itemState & ODS_SELECTED))
);
if( bsel )
{
CBrush brush( RGB(0 ,0 ,255)); // bleue
pBrush = pDC->SelectObject( &brush );
pDC->FillRect(&rect, &brush);
pDC->SetTextColor(RGB(255,255,0)); // jaune
pDC->SetBkColor( RGB(0 ,0 ,255) ); // bleue
pDC->SelectObject( pBrush );
}
else
{
// couleur alternative :
CBrush brush((nItem %2)==0?RGB(0 ,255,0):RGB(128,128,0));
pBrush = pDC->SelectObject( &brush );
pDC->FillRect(&rect, &brush);
pDC->SetTextColor( RGB(0 ,0 ,0));
pDC->SetBkColor( (nItem %2)==0?RGB(0 ,255,0):RGB(128,128,0) );
pDC->SelectObject( pBrush );
}
CString s;
int nNoColumn, nWidthColumn;
int nNbColumns = GetHeaderCtrl()->GetItemCount();
int ncx=0;
LV_COLUMN lvc;
char szItem[255];
LVITEM LvItem;
for( nNoColumn = 0; nNoColumn < nNbColumns ; nNoColumn++ )
{
nWidthColumn = GetColumnWidth( nNoColumn );
lvc.mask = LVCF_FMT;
if( GetColumn( nNoColumn, &lvc ) ==0 ) continue;
LvItem.mask=LVIF_TEXT;
LvItem.cchTextMax=sizeof(szItem);
LvItem.pszText=szItem;
LvItem.iItem=nItem;
LvItem.iSubItem=nNoColumn;
GetItem( &LvItem );
s=LvItem.pszText;
if( lvc.fmt & LVCFMT_RIGHT )
{
pDC->SetTextAlign( TA_RIGHT );
s += ' ';
pDC->ExtTextOut( r.left + nWidthColumn , r.top, ETO_OPAQUE|ETO_CLIPPED, &r, s, NULL );
}
else
{
pDC->SetTextAlign( TA_LEFT );
s = ' ' + s;
pDC->ExtTextOut( r.left ,r.top, ETO_OPAQUE|ETO_CLIPPED, &r, s, NULL );
}
r.left += nWidthColumn;
}
pDC->RestoreDC( nSavedDC );
if( lpDrawItemStruct->itemState & ODS_SELECTED )
pDC->DrawFocusRect( &lpDrawItemStruct->rcItem );
} |
Partager