You first need to rewrite the Ctreecontrl and then add it in. h
afx_msg void Ondblclktree (nmhdr* pnmhdr, lresult* pResult);//double-click event
afx_msg void Onclktree (nmhdr* pnmhdr, lresult* PResult);//Click event
. h file
#pragma once
/////////////////////////////////////////////////////////////////////////////
//CViewTree Window
class Cviewtree:public CTreeCtrl
{
//Construction public
:
cviewtree ();
Rewrite
protected:
virtual BOOL onnotify (WPARAM WPARAM, LPARAM LPARAM, lresult* pResult);
Implement public
:
virtual ~cviewtree ();
afx_msg void Ondblclktree (nmhdr* pnmhdr, lresult* pResult);
afx_msg void Onclktree (nmhdr* pnmhdr, lresult* pResult);
Protected:
declare_message_map ()
};
. cpp Files
#include "stdafx.h" #include "ViewTree.h" #ifdef _DEBUG #define NEW debug_new #undef this_file static char this_file[] =
__file__; #endif///////////////////////////////////////////////////////////////////////////////CViewTree CViewTree:: Cviewtree () {} cviewtree::~cviewtree () {} begin_message_map (Cviewtree, CTreeCtrl) on_notify_reflect (NM_DBLCLK, &C Viewtree::ondblclktree) On_notify_reflect (Nm_click, &cviewtree::onclktree) end_message_map ()///////////////// Cviewtree Message Handler BOOL cviewtree::onnotify (WPARAM
WParam, LPARAM LPARAM, lresult* pResult) {BOOL bRes = ctreectrl::onnotify (WParam, LPARAM, PResult);
nmhdr* PNMHDR = (nmhdr*) LParam;
ASSERT (Pnmhdr! = NULL); if (pnmhdr && pnmhdr->code = = Ttn_show && gettooltips ()! = NULL) {gettooltips ()->setwindowpos (&A Mp;wndtop,-1,-1,-1,-1, Swp_nomove | Swp_noactivate |
Swp_nosize);
} return bRes; } void Cviewtree::ondblclktree (nmhdr* Pnmhdr, lresult* pResult) {Htreeitem Htreeitem = GetSelectedItem ();
Take the GetItemText () function as an example: CString S1 = GetItemText (Htreeitem);
AfxMessageBox ("You have selected" +S1);
*presult = 0;
} void Cviewtree::onclktree (nmhdr* pnmhdr, lresult* pResult) {Htreeitem Htreeitem = GetSelectedItem ();
Take the GetItemText () function as an example: CString S1 = GetItemText (Htreeitem);
AfxMessageBox ("You have selected" +S1);
*presult = 0; }
This enables Ctreecontrl click events and double-click events