因为我只想选定给定数目以内的checkbox,在tree control的OnNMClick中处理响应消息,如果已经达到数量不能setcheck了,就不让checkbox打钩我在OnNMClick中判断数量是否已经达到了,然后setcheck(hTreeItem,FALSE); 点击完后checkbox还是会自动打上勾请问如何使点击未打钩的CTreeCtrl 的checkbox让他依然不打钩

解决方案 »

  1.   

    When the user clicks the check box of a TreeView item, an NM_CLICK notification is sent to the parent window. When this occurs, the TVM_HITTEST message returns TVHT_ONITEMSTATEICON. The TreeView control uses this same condition to toggle the state of the check box. Unfortunately, the TreeView control toggles the state after the NM_CLICK notification is sent.
    因此你setcheck被treeview自己覆盖掉了。
    你可以Post个message,使得父窗口在treeview处理完后再setcheck。相当于延迟调用。
      

  2.   

    试试自定义消息。在自定义消息里setcheck,在OnNMClick中postmessage