How to change the background color of checkbox in CListCtrl?
-
How to change the background color of checkbox in CListCtrl? The checkbox appears before the 1st column. if I change the background using m_cLstCtrl.SetBkColor(RGB(0,0,0)); the background of the entire control is changed. If I change it inside OnCustomDraw as below: void CSysWindow::OnCustomDrawAlarmLine ( NMHDR* pNMHDR, LRESULT* pResult ) { NMLVCUSTOMDRAW *pCD = (NMLVCUSTOMDRAW*)pNMHDR; // By default set the return value to do the default behavior. *pResult = CDRF_DODEFAULT ; //obtain row and column of item int iRow = pCD->nmcd.dwItemSpec; int iCol = pCD->iSubItem; //Remove standard highlighting of selected (sub)item. pCD->nmcd.uItemState = CDIS_DEFAULT; switch( pCD->nmcd.dwDrawStage ) { case CDDS_PREPAINT: // First stage (for the whole control) { *pResult = CDRF_NOTIFYITEMDRAW; } break; case CDDS_ITEMPREPAINT: { *pResult = CDRF_NOTIFYSUBITEMDRAW; } break; case CDDS_ITEMPREPAINT | CDDS_SUBITEM : // Stage three { if ((iCol != 0) || (iCol != 1)) { pCD->clrText = RGB(255,0,0); pCD->clrTextBk = RGB(0,0,0); } if ((iCol == 0) || (iCol == 1)) { pCD->clrText = RGB(255,0,0); pCD->clrTextBk = RGB(0,255,0); } //if (sub)item is of interest, set custom text/background color //if( 1 == iRow && 3 == iCol ) //{ // pCD->clrText = RGB(255,0,0); // pCD->clrTextBk = RGB(210,245,245); //} //else //{ // pCD->clrText = RGB(0,0,0); // pCD->clrTextBk = RGB(255,255,255); //} *pResult = CDRF_NOTIFYPOSTPAINT; } break; case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: // Stage four (called for each subitem of the focused item) { } break; default:// it wasn't a notification that was interesting to us. { *pResult = CDRF_DODEFAULT; } break; } } The background of the other column gets changed. but not the Checkbox. So...How to change the background of the checkbox column alone?
-
How to change the background color of checkbox in CListCtrl? The checkbox appears before the 1st column. if I change the background using m_cLstCtrl.SetBkColor(RGB(0,0,0)); the background of the entire control is changed. If I change it inside OnCustomDraw as below: void CSysWindow::OnCustomDrawAlarmLine ( NMHDR* pNMHDR, LRESULT* pResult ) { NMLVCUSTOMDRAW *pCD = (NMLVCUSTOMDRAW*)pNMHDR; // By default set the return value to do the default behavior. *pResult = CDRF_DODEFAULT ; //obtain row and column of item int iRow = pCD->nmcd.dwItemSpec; int iCol = pCD->iSubItem; //Remove standard highlighting of selected (sub)item. pCD->nmcd.uItemState = CDIS_DEFAULT; switch( pCD->nmcd.dwDrawStage ) { case CDDS_PREPAINT: // First stage (for the whole control) { *pResult = CDRF_NOTIFYITEMDRAW; } break; case CDDS_ITEMPREPAINT: { *pResult = CDRF_NOTIFYSUBITEMDRAW; } break; case CDDS_ITEMPREPAINT | CDDS_SUBITEM : // Stage three { if ((iCol != 0) || (iCol != 1)) { pCD->clrText = RGB(255,0,0); pCD->clrTextBk = RGB(0,0,0); } if ((iCol == 0) || (iCol == 1)) { pCD->clrText = RGB(255,0,0); pCD->clrTextBk = RGB(0,255,0); } //if (sub)item is of interest, set custom text/background color //if( 1 == iRow && 3 == iCol ) //{ // pCD->clrText = RGB(255,0,0); // pCD->clrTextBk = RGB(210,245,245); //} //else //{ // pCD->clrText = RGB(0,0,0); // pCD->clrTextBk = RGB(255,255,255); //} *pResult = CDRF_NOTIFYPOSTPAINT; } break; case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: // Stage four (called for each subitem of the focused item) { } break; default:// it wasn't a notification that was interesting to us. { *pResult = CDRF_DODEFAULT; } break; } } The background of the other column gets changed. but not the Checkbox. So...How to change the background of the checkbox column alone?
-
Your code seems to be changing different columns. Try modifying the code so it only affects column 0 (where the checkbox is) and see what happens.
The complete background is not changing