Use the ctreectrl Control

Source: Internet
Author: User

It took a day to finally simulate a decent QQ-style interface. Although it is not like a drawer, it still feels a bit like a whole.

The following code is provided:

Bool cuserlist: oninitdialog () {cdialog: oninitdialog (); // todo: add an additional initialization crect rect here; getclientrect (rect ); // cbutton * BTN = (cbutton *) getdlgitem (idc_button1); // BTN-> movewindow (110,10, rect. width ()-205, rect. height ()-295); ctreectrl * m_ctrltree = (ctreectrl *) getdlgitem (idc_tree1); m_ctrltree-> movewindow (, rect. width (), rect. height ()-50); imagelist. create (16, 16, ilc_mask | ilc_color32, 1, 1); // only one icon IM is displayed. Agelist_addicon (imagelist. m_himagelist, afxgetapp ()-> loadicon (idi_collapse); imagelist_addicon (imagelist. m_himagelist, afxgetapp ()-> loadicon (idi_expand); imagelist_addicon (imagelist. m_himagelist, afxgetapp ()-> loadicon (idi_collapse1); imagelist_addicon (imagelist. m_himagelist, afxgetapp ()-> loadicon (idi_expand1); m_ctrltree-> setimagelist (& imagelist, tvsil_state); static htreeitem hparent = tvi_root; HPA Rent = m_ctrltree-> insertitem (tvif_text | tvif_state | tvif_param, _ T ("My friends (5/5)"), 0, 1, indextostateimagemask (1), tvis_stateimagemask, 1, tvi_root, tvi_last); m_ctrltree-> ensurevisible (hparent); m_ctrltree-> insertitem (_ T ("Zhang Xueyou"), hparent ); m_ctrltree-> insertitem (_ T ("guo Fu Cheng"), hparent); m_ctrltree-> insertitem (_ T ("Dawn"), hparent ); m_ctrltree-> insertitem (_ T (""), hparent); m_ctrltree-> insertitem (_ T ("Andy Lau"), hparent); H Parent = m_ctrltree-> insertitem (tvif_text | tvif_state | tvif_param, _ T ("Enterprise friends (5/5)"), 0, 1, indextostateimagemask (1), parent, 1, tvi_root, tvi_last); m_ctrltree-> ensurevisible (hparent); m_ctrltree-> insertitem (_ T ("Product Center"), hparent ); m_ctrltree-> insertitem (_ T ("Technology Center"), hparent); m_ctrltree-> insertitem (_ T ("after-sales service"), hparent ); m_ctrltree-> insertitem (_ T ("Sales Department"), hparent); m_ctrltree-> insertitem (_ T ("Shenzhen Branch"), h Parent); m_ctrltree-> Expand (hparent, subject); hparent = m_ctrltree-> insertitem (tvif_text | tvif_state | tvif_param, _ T ("non-instant message contact (2/12 )"), 0, 1, indextostateimagemask (1), tvis_stateimagemask, 1, tvi_root, tvi_last); m_ctrltree-> insertitem (_ T ("night and night"), hparent ); m_ctrltree-> insertitem (_ T ("Traveling separately"), hparent); m_ctrltree-> insertitem (_ T ("dawn of Late Autumn"), hparent ); m_ctrltree-> insertitem (_ T ("back to the past"), hparent); m_ctrltree-> inser Titem (_ T ("too"), hparent); m_ctrltree-> Expand (hparent, tve_expand); hparent = m_ctrltree-> insertitem (tvif_text | tvif_state | tvif_param, _ T ("blacklist user (1/25)"), 0, 1, indextostateimagemask (1), tvis_stateimagemask, 1, tvi_root, tvi_last ); m_ctrltree-> insertitem (_ T ("Winter"), hparent); m_ctrltree-> insertitem (_ T ("Summer"), hparent ); m_ctrltree-> insertitem (_ T ("Autumn"), hparent); m_ctrltree-> insertitem (_ T ("Spring"), hparent); m_ctrltree-> Insertitem (_ T ("tomorrow"), hparent); Return true;} void cuserlist: onnmdblclktree1 (nmhdr * pnmhdr, lresult * presult) {// todo: add the control notification handler Code * presult = 0; ctreectrl * m_ctrltree = (ctreectrl *) getdlgitem (idc_tree1); htreeitem = m_ctrltree-> getselecteditem (); if (m_ctrltree-> getchilditem (htreeitem) = NULL) {ctalk * ptalk = new ctalk; ptalk-> Create (idd_talk, null); cstring STR = m_ctrltree-> getitemtext (htreei TEM); ptalk-> setwindowtext (_ T ("You are chatting with") + STR + _ T ("chatting"); ptalk-> showwindow (sw_normal); talk. push_back (ptalk); // selected container} void cuserlist: onnmclicktree1 (nmhdr * pnmhdr, lresult * presult) {// todo: add the control notification handler Code * presult = 0; ctreectrl * m_ctrltree = (ctreectrl *) getdlgitem (idc_tree1); cpoint point;: getcursorpos (& Point ); m_ctrltree-> screentoclient (& Point); htreeitem = m_ctrltree-> hittest (point); // returns The current position of the cursor related to the ctreectrl objectif (htreeitem = NULL) return; If (m_ctrltree-> getchilditem (htreeitem) = NULL) // retrieves the child of a specified Tree View itemreturn; uint nstate = m_ctrltree-> getitemstate (htreeitem, tvis_expanded); If (nstate & tvis_expanded )! = 0) // shrink the list item {m_ctrltree-> setitemstate (htreeitem, indextostateimagemask (tve_collapse), partial); m_ctrltree-> sendmessage (tvm_expand, (wparam) (uint) (tve_collapse | gradient), (lparam) (htreeitem);} else {m_ctrltree-> setitemstate (htreeitem, partial (partial), partial); m_ctrltree-> sendmessage (partial, partial, (wparam) (uint) (tve_expand | tve_expandpartial), (lparam) (htreeitem);} m_ctrltree-> invalidate ();}

The cuserlist window object is a Child Window of cxxdlg. The Chat Window pointer created by create is placed in the vector container and released together in the destructor.

Cuserlist ::~ Cuserlist () {STD: vector <ctalk *>: iterator it; // defines the iterator for (IT = talk. Begin (); it! = Talk. End (); It ++) {Delete * it;} talk. Clear (); // clear container}

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.