Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to change the background color of checkbox in CListCtrl?

How to change the background color of checkbox in CListCtrl?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manoharbalu
    wrote on last edited by
    #1

    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?

    L 1 Reply Last reply
    0
    • M manoharbalu

      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?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • L Lost User

        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.

        M Offline
        M Offline
        manoharbalu
        wrote on last edited by
        #3

        The complete background is not changing

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups