Use the EDIT function in TreeCtrl. - a little complement to the programmer's base camp "using the EDIT function"

zhaozj2021-02-11  185

Previously, some people often asked how to save the contents edited in Treectrl, although CodeGuru has a related article, but someone else said.

First, this TreeEList should use the TVS_EDitlabels style, specify when creating resources, or specify when using CREATE, or change in PrecreateWindos (). My code is: const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_EDITLABELS; if (m_wndTree1.Create (dwViewStyle, rectDummy, & m_wndTabs, 2) || m_wndTree2.Create (dwViewStyle, rectDummy, & m_wndTabs, 3!! )) {Trace0 ("failed to create workspace view / n"); return -1; // fail to create}

The red part is the key! This way you can edit your title by now TreeItem!

Next, you need to handle TVN_BEGINLABELEDIT and TVN_ENDLABELEDIT messages.

Void CMYTREE: ONBEGINLABELEDIT (NMHDR * PNMHDR, LRESULT * PRESULT)

{

Tv_dispinfo * ptvdispinfo = (TV_Dispinfo *) PNMHDR;

// limited text length

GetEditControl () -> LimitText (127);

* PRESULT = 0;

}

If the TVN_ENDLABELEDIT message is not processed, the changes in text will not take effect. Void coutline :: Onendlabeledit (NmHDR * pnmhdr, lresult * presult) - {getEtTControl () -> getWindowText (s); // set result to true to accept the change:} Note: The above code is from Sens Ocean "uses the EDIT function in Treelist"

Here, you can create a category, cmytree, then add TVN_BEGINLABELEDIT and TVN_ENDLABELEDIT messages through ClassWizard

ClassWizard's code for us is:

protected: // {{AFX_MSG (CMyTree) afx_msg void OnBeginlabeledit (NMHDR * pNMHDR, LRESULT * pResult); afx_msg void OnEndlabeledit (NMHDR * pNMHDR, LRESULT * pResult); //}} AFX_MSG

Ok, you can edit it by TreeItem, you can edit it! Oh, the younger brother first post, I also hope that everyone will bear.

转载请注明原文地址:https://www.9cbs.com/read-5975.html

New Post(0)