From: mosfet on
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 ?
From: mosfet on
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 ?
From: GT on
"mosfet" <richom.v(a)free.fr> wrote in message
news:45d45ced$0$26337$426a74cc(a)news.free.fr...
> 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 ?

A stab in the dark as I have not tried this, but how about creating your own
MyHeaderCtrl class derived from CHeaderCtrl class and use an object of this
type on your list control. In your MyHeaderCtrl class, catch the message
that sets the background color - I can't remember what it is, but you would
find it in the MSDN.


From: mosfet on
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();
}
From: AliR (VC++ MVP) on
Here is a good article on how to subclass the listctrl's header control.

http://www.codeproject.com/listctrl/headerctrl.asp

AliR.

"mosfet" <richom.v(a)free.fr> wrote in message
news:45d45ced$0$26337$426a74cc(a)news.free.fr...
> 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 ?