Ctreecontrl implementation in VC respond to a click or double-tap event

Source: Internet
Author: User

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

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.