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 a checkbox in a list control?

how to change the background color of a checkbox in a list control?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
7 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.
  • T Offline
    T Offline
    tataxin
    wrote on last edited by
    #1

    I have a list control CListCtrl with report view and the extend style of LVS_EX_CHECKBOXES. Then I try to change the back ground color of the list control, to black color for example. It's done by overriding OnNMCustomdraw() method. Everything works well except the background color of all checkboxes. Now I don't know how to fix this problem. Any suggestion should be appreciated.

    H 1 Reply Last reply
    0
    • T tataxin

      I have a list control CListCtrl with report view and the extend style of LVS_EX_CHECKBOXES. Then I try to change the back ground color of the list control, to black color for example. It's done by overriding OnNMCustomdraw() method. Everything works well except the background color of all checkboxes. Now I don't know how to fix this problem. Any suggestion should be appreciated.

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      See XListCtrl - A custom-draw list control with subitem formatting[^].

      T 1 Reply Last reply
      0
      • H Hamid Taebi

        See XListCtrl - A custom-draw list control with subitem formatting[^].

        T Offline
        T Offline
        tataxin
        wrote on last edited by
        #3

        Thank you for your reply, Hamid. I'll have a look at it now

        T 1 Reply Last reply
        0
        • T tataxin

          Thank you for your reply, Hamid. I'll have a look at it now

          T Offline
          T Offline
          tataxin
          wrote on last edited by
          #4

          it's quite complicated, so I still not success, :(( but anyway, thanks for your help. I will look at this later

          H 1 Reply Last reply
          0
          • T tataxin

            it's quite complicated, so I still not success, :(( but anyway, thanks for your help. I will look at this later

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            Did you see it I guess your problem is solved. :)

            T 1 Reply Last reply
            0
            • H Hamid Taebi

              Did you see it I guess your problem is solved. :)

              T Offline
              T Offline
              tataxin
              wrote on last edited by
              #6

              Not yet, Hamid, :( If I success, I will notify it here. And if you find something, plz let me know, :)

              T 1 Reply Last reply
              0
              • T tataxin

                Not yet, Hamid, :( If I success, I will notify it here. And if you find something, plz let me know, :)

                T Offline
                T Offline
                tataxin
                wrote on last edited by
                #7

                I did it, not very well but it works. Actually, I try to do similarly to XListCtrl All I did here: I have a class MyListCtr direved from CListCtrl. Then I override OnNMCustomdraw, try to draw the rectangualar with specificed color (black in my case). The problem is how to catch event mouse click, determine checkbox state and change the drawing. I cannot understand the way XListCtrl do, it seems to register a defined event WM_XLISTCTRL_CHECKBOX_CLICKED, but I'm not sure. And TRACE, what is TRACE macro? hehe So I did like this: use event NM_CLICK

                void CMyDlg::OnNMClickListData(NMHDR *pNMHDR, LRESULT *pResult)
                {
                /* get check box state */
                NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
                *pResult = 0;

                if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
                	return;	// No change
                
                BOOL bPrevState = (BOOL)(((pNMListView->uOldState &
                			LVIS\_STATEIMAGEMASK)>>12)-1);   // Old check box state
                if (bPrevState < 0)	// On startup there's no previous state 
                	bPrevState = 0; // so assign as false (unchecked)
                
                // New check box state
                BOOL bChecked=(BOOL)(((pNMListView->uNewState & LVIS\_STATEIMAGEMASK)>>12)-1);
                if (bChecked < 0) // On non-checkbox notifications assume false
                	bChecked = 0;
                
                if (bPrevState == bChecked) // No change in check box
                	return;	
                

                }

                I'd tried some ways but not success until this. Actually, I found it somewhere else.

                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