CheckBox usage for C + + CTreeView _c language

Source: Internet
Author: User

1. Message Events

(1) mouse clicks on the current item checkbox: Raises Nm_click event and passes Tvht_onitemstateicon.
(2) The mouse clicks the current item text: Raises the Nm_click event.
(3) mouse clicks on the new Item checkbox: Raises tvn_selchanged event, Nm_click event and passes Tvht_onitemstateicon.
(4) Mouse clicks the new item text: Raises Nm_click event, tvn_selchanged event.

2. Summary of Message Events

Clicking on the item raises the Nm_click event. If you click on the checkbox, pass Tvht_onitemstateicon.
Therefore, the Tvn_selchanged event is not handled and only the Nm_click event is handled.

3. Message Processing considerations

(1) Clicking the checkbox automatically updates the state of the checkbox, so you do not need to use the SetCheck function to set the state in the processing code, and the Getcheck function returns its original state.
(2) Click on the new checkbox will not automatically set the corresponding item to select the state, you need to use the SelectItem function to set.

4. How to use

(1) If the transmission of Tvht_onitemstateicon
Gets the status of the selected item and takes the counter
If there are subkeys, all subkeys are set to consistent
If there are no subkeys
If the current state is true, set the parent to true, otherwise traverse all siblings, or false to set the parent to false.
If new item is selected, set new item to select item
(2) if not delivered Tvht_onitemstateicon
Set update item status, GET status of select item
If there are subkeys, all subkeys are set to consistent
If there are no subkeys
If the current state is true, set the parent to true, otherwise traverse all siblings, or false to set the parent to false.

5. Function code in response to Nm_click event

 void Ctesttimerdlg::onclicktree (nmhdr* pnmhdr, lresult* pResult) {//Todo:add your CO
  Ntrol Notification Handler code here CPoint point;                 UINT Uflag;
  An integer htreeitem htree that receives information about the hit test;
  BOOL bcheck;            GetCursorPos (&point);      Gets the screen mouse coordinate m_treectrl.screentoclient (&point);  Convert to Customer coordinates htree = M_treectrl.hittest (Point,&uflag);
  Returns the current position of the cursor associated with the Ctreettrl and the handle if ((Tvht_nowhere & Uflag)) {return;
    } if (Htree && (Tvht_onitemstateicon & Uflag))//point check box {m_treectrl.selectitem (htree);
    CString temp = M_treectrl.getitemtext (htree) + "\ r \ n";
    TRACE (temp);   bcheck = M_treectrl.getcheck (Htree);       Gets the current check state setchildcheck (Htree,!bcheck);       Set subkey check state Setparentcheck (Htree, bcheck);
Sets the parent Shang state} *presult = 0; }

 void Ctesttimerdlg::setchildcheck (Htreeitem htree,bool bcheck) {M_treectrl.expand (HTree,
  Tve_expand); Htree = M_treectrl.getchilditem (Htree);   
    Gets the subkey handle while (Htree) {M_treectrl.setcheck (Htree, bcheck);      Setchildcheck (Htree,bcheck);  Recursive Call Htree = M_treectrl.getnextsiblingitem (Htree); Gets the sibling's handle}} 
void Ctesttimerdlg::setparentcheck (Htreeitem htree,bool bcheck)
{
  Htreeitem hparent = m_ Treectrl.getparentitem (htree);
  if (hparent)
  {
    Htreeitem hchild = M_treectrl.getchilditem (hparent);
    while (Hchild)
    {
      if (hchild = = Htree)
      {
        hchild = M_treectrl.getnextsiblingitem (hchild);
        Continue;
      }
      BOOL bflag = M_treectrl.getcheck (hchild);
      if (bcheck = = bflag)         //Judge if there are any siblings selected
      {return
        ;
      }
      Hchild = M_treectrl.getnextsiblingitem (Hchild);
    }
    M_treectrl.setcheck (Hparent,!bcheck);
    Setparentcheck (Hparent,bcheck);       Set the state of the parent item
  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.