Microsoft Developer Network > Forenhomepage > Visual C++ General > How to solve this CCheckListBox problem?
Stellen Sie eine FrageStellen Sie eine Frage
 

FrageHow to solve this CCheckListBox problem?

  • Mittwoch, 4. November 2009 14:50shantou chen TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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

Alle Antworten

  • Mittwoch, 4. November 2009 15:22Scott McPhillipsMVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    See the code for CCheckListBox::OnChildNotify.  It is called just before DrawItem.  It draws the check and can be overridden.
  • Mittwoch, 4. November 2009 17:42shantou chen TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    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

  • Mittwoch, 4. November 2009 23:52Scott McPhillipsMVPTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    The MFC resources, including that bitmap, are in afxres.rc

    Don't know about question 2.