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}