Re: CListCtrl in report mode and column header
mosfet a ?crit :
mosfet a ?crit :
Hi,
I would like to have a CListCtrl in report mode with columnheader but
I would like the column header to be transparent and without
displaying separators.
How can I do that ?
Or same question : HOW CAN I CHANGE COLUMN HEADER COLOR ?
Ok I found it :
//---------------------------------------------------------------------------//
// class CHeaderCtrlEx
//---------------------------------------------------------------------------//
CHeaderCtrlEx::CHeaderCtrlEx()
{
}
CHeaderCtrlEx::~CHeaderCtrlEx()
{
}
BEGIN_MESSAGE_MAP(CHeaderCtrlEx, CHeaderCtrl)
//{{AFX_MSG_MAP(CColorHeaderCtrl)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
//
// CHeaderCtrlEx message handlers
//
//---------------------------------------------------------------------------
// CHeaderCtrlEx::OnCustomDraw
//
// Handles custom draw
//
void CHeaderCtrlEx::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;
}
else if(dwDrawStage == CDDS_ITEMPREPAINT)
{
HDC hDC = pCD->hdc;
SetTextColor(hDC, RGB(255, 255, 255));
if(dwItemSpec)
SetBkColor(hDC, RGB( 0, 0, 255)); // Blue
else
SetBkColor(hDC, RGB( 255, 0, 0)); // Red
*pResult = CDRF_NEWFONT;
}
}
// CColorHeaderCtrl::OnEraseBkgnd
//
// This is where we specify the background color of the header
//
BOOL CHeaderCtrlEx::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
GetClientRect(&rc);
pDC->FillSolidRect(&rc, RGB(255, 255, 0)); // Yellow
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
//BOOL CHeaderCtrlEx::Init(CHeaderCtrl *pHeader)
//{
// ASSERT(pHeader && pHeader->GetSafeHwnd());
// if (!SubclassWindow(pHeader->GetSafeHwnd()))
// {
// OutputDebugString(_T("Unable to subclass existing header!\n"));
// return FALSE;
// }
//
// return TRUE;
//}
//---------------------------------------------------------------------------//
// class CHistoryListCtrl
//---------------------------------------------------------------------------//
IMPLEMENT_DYNAMIC(CHistoryListCtrl, CListCtrl)
CHistoryListCtrl::CHistoryListCtrl()
{
}
CHistoryListCtrl::~CHistoryListCtrl()
{
}
BEGIN_MESSAGE_MAP(CHistoryListCtrl, CListCtrl)
ON_WM_CREATE()
END_MESSAGE_MAP()
int CHistoryListCtrl::SubclassHeader()
{
CHeaderCtrl* pHeader;
int nRval = 0;
pHeader = GetHeaderCtrl();
if(pHeader && pHeader->GetSafeHwnd()){
if(!m_hdr.SubclassWindow(pHeader->GetSafeHwnd()))
nRval = -1;
}
return nRval;
}
void CHistoryListCtrl::PreSubclassWindow()
{
// Use REPORT mode
ModifyStyle(0, LVS_REPORT);
//-- Subclassing header with our custom --//
SubclassHeader();
CListCtrl::PreSubclassWindow();
}
//---------------------------------------------------------------------------
//
// CHistoryListCtrl message handlers
//
//---------------------------------------------------------------------------
int CHistoryListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
//-- Subclassing header with our custom --//
return SubclassHeader();
}