Microsoft 开发人员网络 > 论坛主页 > Visual C++ General > How to solve this CCheckListBox problem?
提出问题提出问题
 

问题How to solve this CCheckListBox problem?

  • 2009年11月4日 14:50shantou chen 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    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

全部回复

  • 2009年11月4日 15:22Scott McPhillipsMVP用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    See the code for CCheckListBox::OnChildNotify.  It is called just before DrawItem.  It draws the check and can be overridden.
  • 2009年11月4日 17:42shantou chen 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    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

  • 2009年11月4日 23:52Scott McPhillipsMVP用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    The MFC resources, including that bitmap, are in afxres.rc

    Don't know about question 2.