VC + + CTreeCtrl use Nm_click and tvn_selchanged

Source: Internet
Author: User

This is the handler function Nm_click when the CTreeCtrl control is clicked
voidCdriverselctrl::onnmclick (NMHDR *pnmhdr, LRESULT *PResult)    {CPoint curpoint;    UINT nflags;    Htreeitem HItem; GetCursorPos (&curpoint);//Current Point coordinatesScreenToClient (&curpoint);//screen coordinates converted to tree inner coordinatesHItem = HitTest (Curpoint, &nflags);//whether the coordinates have an item    if(HItem && (Tvht_onitem & nflags))//Judging whether there is Htreeitem    {         This-SelectItem (HItem);//Click here to process the results after clicking}
//TODO: Add control notification handler code here*presult =0;}

It is important to point out here that the HitTest function can detect not only where the item is located on item, but also the description of MSDN.

Value meaning
Tvht_above

Above the client area.

Tvht_below

Below the client area.

Tvht_nowhere

In the client area, but below the last item.

Tvht_onitem

The bitmap or label associated with an item.

Tvht_onitembutton

The button associated with an item.

Tvht_onitemicon

The bitmap associated with an item.

Tvht_onitemindent

In the indentation associated with an item.

Tvht_onitemlabel

The label (string) associated with an item.

Tvht_onitemright

The area to the right of a item.

Tvht_onitemstateicon

On the State, icon for a Tree-view item, is in a user-defined state.

Tvht_toleft

The left of the client area.

Tvht_toright

The right of the client area.

This allows for more flexible use of the Ctreectl control.

For example, the following example:

voidCdriverselctrl::onnmclick (NMHDR *pnmhdr, LRESULT *PResult)    {CPoint point;    UINT Uflag;    BOOL bcheck; GetCursorPos (&Point ); Ctreectrl::screentoclient (&Point ); Htreeitem Htree= Ctreectrl::hittest (Point, &uflag);if(Htree && (tvht_onitemstateicon &Uflag))        {Ctreectrl::selectitem (htree); Bcheck=Ctreectrl::getcheck (Htree);     }    //TODO: Add control notification handler code here*presult =0;}

Here is the function when the option changes

// This is the handler function when the control's selection has changed void Cdriverselctrl::ontvnselchanged (NMHDR *pnmhdr, LRESULT *pResult) {    = Reinterpret_cast<lpnmtreeview >(PNMHDR);p nmtreeview// check htreeitem// last selected Htreeitem// TODO:  Add control notification handler code 0 here ;}

VC + + CTreeCtrl use Nm_click and tvn_selchanged

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.