Le réseau pour les développeurs > Forums - Accueil > Visual C++ General > How to solve this CCheckListBox problem?
Poser une questionPoser une question
 

QuestionHow to solve this CCheckListBox problem?

  • mercredi 4 novembre 2009 14:50shantou chen Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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

Toutes les réponses

  • mercredi 4 novembre 2009 15:22Scott McPhillipsMVPMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    See the code for CCheckListBox::OnChildNotify.  It is called just before DrawItem.  It draws the check and can be overridden.
  • mercredi 4 novembre 2009 17:42shantou chen Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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

  • mercredi 4 novembre 2009 23:52Scott McPhillipsMVPMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    The MFC resources, including that bitmap, are in afxres.rc

    Don't know about question 2.