Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a TreeView Control in MFC.

what i did is, i put some elements in a way into that tree such that, the depth0 elements are alphabets and the depth one elements are numbers as below:-

|
MyTree
| A
| |--1
| |--2
| |--3
|
|---B
| |--4
| |--5
| |--6
|
|---C
| |--7
| |--8
| |--9

Now, i want, when i double click the alphabets, it displays message, that alphabet is chosen, and if i double click numbers, it displays message, that number is chosen.

I even dont know, how to implement the double click event on its items. How to implement this whole thing in..??
Posted
Comments
Sergey Alexandrovich Kryukov 30-May-12 21:51pm    
Is MSDN broken where you work? :-)
What did you try? What's the problem?
--SA
stib_markc 31-May-12 1:23am    
Try TVN_SELCHANGE messages, as SA said. TVN(Tree View Notification)..

You need to handle TVN_SELCHANGING and TVN_SELCHANGED notification messages. Item selection is explained here:
http://msdn.microsoft.com/en-us/library/a9a9f1t7%28v=vs.100%29.aspx[^].

The example here shows how you get the currently selected item:
http://www.codersource.net/MFC/MFCTutorials/MFCTreeusageandexample.aspx[^].

Basically, that's all you need. Now when you know what to look for (keywords for Web search), you can try to find some more detailed code samples.

Good luck,
—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 31-May-12 15:17pm    
Well answered :-D
Sergey Alexandrovich Kryukov 31-May-12 17:18pm    
Thank you, Espen.
--SA
SAKryukov gave you some very important information, I want to add some with this:
You can Process WM_NOTIFY windows message and NM_CLICK action, you can get the proper Tree Object

here is a simple example:

C++
case WM_NOTIFY:
NMHDR *nmhdr;
nmhdr=(NMHDR *)lParam;
switch(nmhdr->code)
{
  case NM_CLICK:
  TVHITTESTINFO tv;
  HTREEITEM htr,htr_tblName;
  RECT rc_tree;
  POINT ms_pt;
  GetCursorPos(&ms_pt);
  GetWindowRect(nmhdr->hwndFrom, &rc_tree);
  tv.pt.x=ms_pt.x-rc_tree.left;
  tv.pt.y=ms_pt.y-rc_tree.top;
  htr=TreeView_HitTest(nmhdr->hwndFrom,&tv); //here is the object of the leaf that got clicked
  
}


good luck
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900