Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
TreeView list:

root
|--aa
|--bb

How can i do when i click aa item show message "aa was clicked",when i click bb item show message "bb was cilcked"?

Only using WINDOWS API No MFC?

please help me,this is really important to me!!

What I have tried:

case WM_NOTIFY:
if(((LPNMHDR)lParam)->code == NM_LCLICK) // Right Click
{
Selected=(HTREEITEM)SendDlgItemMessage (hWndList,
IDC_TREE1,TVM_GETITEM,TVGN_TARET,0);
if(Selected==NULL)
{
MessageBox();
break;
}

SendDlgItemMessage(hWndList,IDC_TREE1,
TVM_SELECTITEM,TVGN_CARET,(LPARAM)Selected);
}
break;

this is what i did,but i can't get the infomation of the item i clicked.
can you give me some advise,codes will be better!thank you!
Posted
Updated 25-Apr-16 22:36pm
Comments
Sergey Alexandrovich Kryukov 26-Apr-16 4:26am    
Are you sure that hWndList is really the dialog, a parent of right tree view?
TVGN_TARET would not compile...
—SA
Member 12484930 26-Apr-16 4:34am    
sorry it's TVGN_CARET,type wrong~
and can you tell me how to get the item i selected?
i want to show a message when i clicked the "aa" item.
can you give me a little code?
i am the beginner on TREEVIEW section please.
Sergey Alexandrovich Kryukov 26-Apr-16 4:38am    
I explained 100% in my answer, it should be more than enough. All you need is to pay more attention while reading MSDN and strictly follow the function profile and the documentation.

Next time, never ever enter code on the Web page, always paste it from real code at least validated by compiling.

—SA

1 solution

You are doing it wrong. You don't pass a pointer to LVITEM structure which is needed to receive the information on the item. Instead, you cast the function result, which merely returns TRUE or FALSE, indicating success or failure, but never a pointer as you incorrectly assumed.

Please see:
LVM_GETITEM message (Windows)[^],
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774760(v=vs.85).aspx[^].

Besides, I'm not sure you correctly use SendDlgItemMessage; you can choose between this function or SendMessage. This is explained here: https://support.microsoft.com/en-us/kb/12273[^].

Alternatively, you can use the macro ListView_GetItem:
ListView_GetItem macro (Windows)[^].

—SA
 
Share this answer
 
v2
Comments
Member 12484930 26-Apr-16 5:18am    
Thank you very much!
Sergey Alexandrovich Kryukov 26-Apr-16 9:43am    
You are very welcome.
Good luck, call again.
—SA

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