Visual C++ Developer Center > Visual C++ Forums > Visual C++ General > How to solve this CCheckListBox problem?
Ask a questionAsk a question
 

QuestionHow to solve this CCheckListBox problem?

  • Wednesday, November 04, 2009 2:50 PMshantou chen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Visual C++ Experts,

    We have a native Visual C++ application that uses CCheckListBox. Under some situations, we want to make each items of the CCheckListBox CHECKED and DISABLED so that user cannot edit them (We cannot disable the CCheckListBox because the scroll bar will be disabled.)

    The problem we have is that when an item is disabled, the text is greyed but the Check Mark is still black. It gives users an impression that it is editable.

    I read the implementation code in WinCtrl3.cpp and saw that the CheckBox is not drawn in DrawItem function. So I cannot fix this problem by overriding DrawItem.

    How to solve this problem?

    Thanks.

    Shantou

All Replies

  • Wednesday, November 04, 2009 3:22 PMScott McPhillipsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    See the code for CCheckListBox::OnChildNotify.  It is called just before DrawItem.  It draws the check and can be overridden.
  • Wednesday, November 04, 2009 5:42 PMshantou chen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Scott,

    Thank you for your suggestion.

    I looked into OnChildNotify and got following impressions:

    For WM_DRAWITEM message, it calls PreDrawItem, and then PreDrawItemNonThemed. The actual code to draw CheckBox is in PreDrawItemNoThemed which copies a Check Mark bitmap to the target location. So I need to override OnChildNotify to call my own PreDrawItem and PreDrawItemNonThemed. 

    I have following questions:
       1. How do I find out the bitmap AFX_IDB_CHECKLISTBOX_95. I would like to see if it contains a disabled and checked bitmap.
       2. The class derived from CCheckListBox cannot use the _AFX_CHECKLIST_STATE object defined in WinCtrl3.cpp.

    Do you have any suggestions to those questions?

    Thanks.

    Shantou

  • Wednesday, November 04, 2009 11:52 PMScott McPhillipsMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The MFC resources, including that bitmap, are in afxres.rc

    Don't know about question 2.