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
|
#include "stdafx.h"
#include "CheckHeadCtrl.h"
CCheckHeadCtrl::CCheckHeadCtrl()
{
}
CCheckHeadCtrl::~CCheckHeadCtrl()
{
}
BEGIN_MESSAGE_MAP(CCheckHeadCtrl, CHeaderCtrl)
//{{AFX_MSG_MAP(CCheckHeadCtrl)
ON_NOTIFY_REFLECT(HDN_ITEMCLICK, &CCheckHeadCtrl::OnItemClicked)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CCheckHeadCtrl::OnCustomDraw)
// ON_WM_ERASEBKGND()
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CCheckHeadCtrl::OnItemClicked(NMHDR* pNMHDR, LRESULT* pResult)
{
NMHEADER* pNMHead = (NMHEADER*)pNMHDR;
*pResult = 0;
int nItem = pNMHead->iItem;
if (0 != nItem)
return;
HDITEM hdItem;
hdItem.mask = HDI_IMAGE;
VERIFY( GetItem(nItem, &hdItem) );
if (hdItem.iImage == 1)
hdItem.iImage = 2;
else
hdItem.iImage = 1;
VERIFY(SetItem(nItem, &hdItem));
BOOL bl = hdItem.iImage == 2 ? TRUE : FALSE;
CListCtrl* pListCtrl = (CListCtrl*)GetParent();
int nCount = pListCtrl->GetItemCount();
for(nItem = 0; nItem < nCount; nItem++)
{
ListView_SetCheckState(pListCtrl->GetSafeHwnd(), nItem, bl);
}
}
void CCheckHeadCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMCUSTOMDRAW* pCD = (NMCUSTOMDRAW*)pNMHDR;
DWORD dwDrawStage,
dwItemSpec;
*pResult = CDRF_DODEFAULT;
dwDrawStage = pCD->dwDrawStage;
dwItemSpec = pCD->dwItemSpec;
if (dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
if (dwDrawStage == CDDS_ITEMPREPAINT)
{
HDC hDC = pCD->hdc;
SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
if (dwItemSpec)
SetBkColor(hDC, RGB( 0, 0, 255)); // Blue
else
SetBkColor(hDC, RGB( 255, 0, 0)); // Red
*pResult = CDRF_NEWFONT;
}
}
|