ianhoc
asked on
changing background color of CListCtrl
I have derived a class CColorListCtrl from CListCtrl and I am trying to change the background color depending on whether the ListCtrl is disabled or not.
I have accomplished similar feats with CEdit and CListBox, but I can't find where to put my code in the CColorListCtrl class.
CTLCOLOR doesn't trap, neither does Create or DrawItem..... any suggestions?
Thanks
Ian (ianhoc@ameritech.net)
I have accomplished similar feats with CEdit and CListBox, but I can't find where to put my code in the CColorListCtrl class.
CTLCOLOR doesn't trap, neither does Create or DrawItem..... any suggestions?
Thanks
Ian (ianhoc@ameritech.net)
Actually I just tried a sample prog and I guess I couldn't get the backround color set with
SetBkColor( COLORREF cr );
to show through.
So I just called
SetBkColor( COLORREF cr );
and
SetTextBkColor(COLORREF cr);
with the same color and it works like a charm.
SetBkColor( COLORREF cr );
to show through.
So I just called
SetBkColor( COLORREF cr );
and
SetTextBkColor(COLORREF cr);
with the same color and it works like a charm.
>> CTLCOLOR doesn't trap
Do you understand that the WM_CTLCOLOR messages are sent to the window that is the PARENT of the control. this way the parent window can set the color scheme and other appearance attributes of all the controls on the window. So were you looking for this message on the list control window, or its parent window?
Do you understand that the WM_CTLCOLOR messages are sent to the window that is the PARENT of the control. this way the parent window can set the color scheme and other appearance attributes of all the controls on the window. So were you looking for this message on the list control window, or its parent window?
Have you tried trapping NM_CUSTOMDRAW messages? You then need to check what drawing stage is happening. I've used the code below to get an alternating colour effect for the lines in a list control, amongst other things.
(The namespaced items are only there for autocompletion in Visual Studio 6 - VS .Net shouldn't need them.)
void CAxEREnquiryListCtrl::OnCu stomDraw(N MHDR* pNMHDR, LRESULT* pResult)
{
BOOL bRowColourToggle = FALSE;
NMLVCUSTOMDRAW * plvcd = reinterpret_cast<NMLVCUSTO MDRAW *>(pNMHDR);
BOOL bHandled = TRUE;
CListCtrl * pList = GetListCtrl();
if(plvcd){
switch(plvcd->nmcd.dwDrawS tage){
case CONS_LVCD::CD_MSGS::dwCDDS _PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CONS_LVCD::CD_MSGS::dwCDDS _ITEMPREPA INT:
if(pList->m_hWnd == plvcd->nmcd.hdr.hwndFrom){
bRowColourToggle = (plvcd->nmcd.dwItemSpec % 2);
plvcd->clrTextBk = bRowColourToggle ?
CONS_COLORS::ORDINALS::cre faryListSt ripes[CONS _COLORS::O RDINALS::d wCO_Enquir yListBack1 ] :
CONS_COLORS::ORDINALS::cre faryListSt ripes[CONS _COLORS::O RDINALS::d wCO_Enquir yListBack2 ] ;
plvcd->clrText = CONS_COLORS::crefEnquiries TextForeGr ound;
}
*pResult = CDRF_NEWFONT;
//*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CONS_LVCD::CD_MSGS::dwCDDS _ITEMPREPA INT | CONS_LVCD::CD_MSGS::dwCDDS _SUBITEM:
plvcd->clrText = RGB(0xCC, 0xCC, 0xCC);
plvcd->clrTextBk = RGB(0xEE, 0xEE, 0xEE);
*pResult = CDRF_NEWFONT;
break;
default:
bHandled = FALSE;
}
}
}
(The namespaced items are only there for autocompletion in Visual Studio 6 - VS .Net shouldn't need them.)
void CAxEREnquiryListCtrl::OnCu
{
BOOL bRowColourToggle = FALSE;
NMLVCUSTOMDRAW * plvcd = reinterpret_cast<NMLVCUSTO
BOOL bHandled = TRUE;
CListCtrl * pList = GetListCtrl();
if(plvcd){
switch(plvcd->nmcd.dwDrawS
case CONS_LVCD::CD_MSGS::dwCDDS
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CONS_LVCD::CD_MSGS::dwCDDS
if(pList->m_hWnd == plvcd->nmcd.hdr.hwndFrom){
bRowColourToggle = (plvcd->nmcd.dwItemSpec % 2);
plvcd->clrTextBk = bRowColourToggle ?
CONS_COLORS::ORDINALS::cre
CONS_COLORS::ORDINALS::cre
plvcd->clrText = CONS_COLORS::crefEnquiries
}
*pResult = CDRF_NEWFONT;
//*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CONS_LVCD::CD_MSGS::dwCDDS
plvcd->clrText = RGB(0xCC, 0xCC, 0xCC);
plvcd->clrTextBk = RGB(0xEE, 0xEE, 0xEE);
*pResult = CDRF_NEWFONT;
break;
default:
bHandled = FALSE;
}
}
}
ASKER
Thanks for the input here guys:
Frogger, where did you put the code
"SetBkColor( COLORREF cr );
and
SetTextBkColor(COLORREF cr);" ?
I can't seem to get it to do anything.
nietod, thanks for enlightening me - a solution would be nice.
pcooke, I tried your code (thanks for the detailed reply!)
I trapped the OnNotify within the CColorListCtrl class wizard, but can find no references to OnCustomDraw. - How would I cath the OnCustomDraw notification - any cahnges to the clrTextBk and clrText have no affect from within OnNotify.
Ian
Frogger, where did you put the code
"SetBkColor( COLORREF cr );
and
SetTextBkColor(COLORREF cr);" ?
I can't seem to get it to do anything.
nietod, thanks for enlightening me - a solution would be nice.
pcooke, I tried your code (thanks for the detailed reply!)
I trapped the OnNotify within the CColorListCtrl class wizard, but can find no references to OnCustomDraw. - How would I cath the OnCustomDraw notification - any cahnges to the clrTextBk and clrText have no affect from within OnNotify.
Ian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
from class CListCtrl
BOOL SetBkColor( COLORREF cr );
doesn't this work?