Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3670
Number of posts: 9122

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
MFC - TreeCtrl problems, clicking an item in a Tree control Posted by Rickard on 25 Oct 2000 at 10:09 AM
Hi!<br>
I'm sitting right here and have a problem... how<br>
to catch a mouse click on a TreeCtrl item??<br>
<br>
a source code exampel would be great!<br>
but it's ok with words to describe how to do it.<br>
<br>
THANKS!<br>
<br>
Using VicualC++ 6.0


Edit Report
Re: MFC - TreeCtrl problems, clicking an item in a Tree control Posted by KMS on 26 Oct 2000 at 7:17 AM
I cant understand what are you looking for! Sorry, but isnt NM_XXX (NM_CLICK etc) enough? Or what are you trying to do exactly?<br>
<br>
: Hi!<br>
: I'm sitting right here and have a problem... how<br>
: to catch a mouse click on a TreeCtrl item??<br>
: <br>
: a source code exampel would be great!<br>
: but it's ok with words to describe how to do it.<br>
: <br>
: THANKS!<br>
: <br>
: Using VicualC++ 6.0<br>
: <br>
<br>



Edit Report
KMS!! KMS!! Posted by Rickard on 27 Oct 2000 at 4:00 AM
KMS<br>
<br>
I don't know how to erite the code right!<br>
If I click one time on TreCtrl and the choose NM_CLICK<br>
in a pop domn menu, then I can edit the code for<br>
clicking the TREE control, not the items.... how to do so it<br>
knows it is an item thats was clicked.<br>
<br>
hope that will work..... :)


Edit Report
Rickard!! Rickard!! Posted by KMS on 27 Oct 2000 at 11:58 AM
I got it now!<br>
<br>
What you need to do is use WM_NOTIFY (Which of course is sent to the parent of the control ) and look for TVN_SELCHANGED.<br>
<br>
For example, say you have IDC_TREE1 on CMyDlg, you would do:<br>
<br>
BOOL CMyDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) <br>
{<br>
LPNM_TREEVIEW p = (LPNM_TREEVIEW) lParam;<br>
if( wParam == IDC_TREE1 && p->hdr.code == TVN_SELCHANGED )<br>
{<br>
// p->itemNew.hItem holds the handle of the new item to be selected.<br>
<br>
// we want to show the text in a message box, so<br>
CHAR szBuffer[ 1024 ];<br>
<br>
TV_ITEM Item;<br>
ZeroMemory( &Item, sizeof( Item ) );<br>
Item.mask = TVIF_TEXT;<br>
Item.hItem = p->itemNew.hItem;<br>
Item.pszText = szBuffer;<br>
Item.cchTextMax = sizeof( szBuffer );<br>
m_MyTree.GetItem( &Item );<br>
AfxMessageBox( szBuffer );<br>
}<br>
<br>
return CDialog::OnNotify(wParam, lParam, pResult);<br>
}<br>
<br>
<br>
: KMS<br>
: <br>
: I don't know how to erite the code right!<br>
: If I click one time on TreCtrl and the choose NM_CLICK<br>
: in a pop domn menu, then I can edit the code for<br>
: clicking the TREE control, not the items.... how to do so it<br>
: knows it is an item thats was clicked.<br>
: <br>
: hope that will work..... :)<br>
: <br>
<br>



Edit Report
KMS!! KMS!! AGAIN :) Posted by Unknown on 27 Oct 2000 at 12:36 PM
I see, but it is a few things I don't realy<br>
understand:<br>
1. LPNM_TREEVIEW<br>
2. hdr (where is it declared, or is it a standard thing?)<br>
3. code(where is it declared, or is it a standard thing?)<br>
<br>
where did you learned this stuff??<br>
<br>
with a book? the web?? pleas tell me!<br>
<br>
now I promise i wont send any more messages! :)<br>
<br>
<br>
: I got it now!<br>
: <br>
: What you need to do is use WM_NOTIFY (Which of course is sent to the parent of the control ) and look for TVN_SELCHANGED.<br>
: <br>
: For example, say you have IDC_TREE1 on CMyDlg, you would do:<br>
: <br>
: BOOL CMyDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) <br>
: {<br>
: LPNM_TREEVIEW p = (LPNM_TREEVIEW) lParam;<br>
: if( wParam == IDC_TREE1 && p->hdr.code == TVN_SELCHANGED )<br>
: {<br>
: // p->itemNew.hItem holds the handle of the new item to be selected.<br>
: <br>
: // we want to show the text in a message box, so<br>
: CHAR szBuffer[ 1024 ];<br>
: <br>
: TV_ITEM Item;<br>
: ZeroMemory( &Item, sizeof( Item ) );<br>
: Item.mask = TVIF_TEXT;<br>
: Item.hItem = p->itemNew.hItem;<br>
: Item.pszText = szBuffer;<br>
: Item.cchTextMax = sizeof( szBuffer );<br>
: m_MyTree.GetItem( &Item );<br>
: AfxMessageBox( szBuffer );<br>
: }<br>
: <br>
: return CDialog::OnNotify(wParam, lParam, pResult);<br>
: }<br>
: <br>
: <br>
: : KMS<br>
: : <br>
: : I don't know how to erite the code right!<br>
: : If I click one time on TreCtrl and the choose NM_CLICK<br>
: : in a pop domn menu, then I can edit the code for<br>
: : clicking the TREE control, not the items.... how to do so it<br>
: : knows it is an item thats was clicked.<br>
: : <br>
: : hope that will work..... :)<br>
: : <br>
: <br>
: <br>
: <br>
<br>



Edit Report
KMS!! KMS!! AGAIN :) Posted by Rickard on 27 Oct 2000 at 12:36 PM
I see, but it is a few things I don't realy<br>
understand:<br>
1. LPNM_TREEVIEW<br>
2. hdr (where is it declared, or is it a standard thing?)<br>
3. code(where is it declared, or is it a standard thing?)<br>
<br>
where did you learned this stuff??<br>
<br>
with a book? the web?? pleas tell me!<br>
<br>
now I promise i wont send any more messages! :)<br>
<br>
<br>
: I got it now!<br>
: <br>
: What you need to do is use WM_NOTIFY (Which of course is sent to the parent of the control ) and look for TVN_SELCHANGED.<br>
: <br>
: For example, say you have IDC_TREE1 on CMyDlg, you would do:<br>
: <br>
: BOOL CMyDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) <br>
: {<br>
: LPNM_TREEVIEW p = (LPNM_TREEVIEW) lParam;<br>
: if( wParam == IDC_TREE1 && p->hdr.code == TVN_SELCHANGED )<br>
: {<br>
: // p->itemNew.hItem holds the handle of the new item to be selected.<br>
: <br>
: // we want to show the text in a message box, so<br>
: CHAR szBuffer[ 1024 ];<br>
: <br>
: TV_ITEM Item;<br>
: ZeroMemory( &Item, sizeof( Item ) );<br>
: Item.mask = TVIF_TEXT;<br>
: Item.hItem = p->itemNew.hItem;<br>
: Item.pszText = szBuffer;<br>
: Item.cchTextMax = sizeof( szBuffer );<br>
: m_MyTree.GetItem( &Item );<br>
: AfxMessageBox( szBuffer );<br>
: }<br>
: <br>
: return CDialog::OnNotify(wParam, lParam, pResult);<br>
: }<br>
: <br>
: <br>
: : KMS<br>
: : <br>
: : I don't know how to erite the code right!<br>
: : If I click one time on TreCtrl and the choose NM_CLICK<br>
: : in a pop domn menu, then I can edit the code for<br>
: : clicking the TREE control, not the items.... how to do so it<br>
: : knows it is an item thats was clicked.<br>
: : <br>
: : hope that will work..... :)<br>
: : <br>
: <br>
: <br>
: <br>
<br>



Edit Report
Re: KMS!! KMS!! AGAIN :) Posted by KMS on 27 Oct 2000 at 2:38 PM
NM_TREEVIEW is in commctrl.h, hdr code etc are members of this structure.<br>
<br>
Learned from books of course! Inside Visual C++, is a good one. Also Using Visual C++ although it spends alot of time on the beginning stuff.<br>
<br>
MSDN CD's is a must also, but I'm sure you have them, I have the Sep 2000 ver on DVD, its fast! I understand that this only comes with MSDN subscription (not free), maybe you can find a friend who has it.<br>
<br>
You are welcome to send new messages! <br>
<br>
: I see, but it is a few things I don't realy<br>
: understand:<br>
: 1. LPNM_TREEVIEW<br>
: 2. hdr (where is it declared, or is it a standard thing?)<br>
: 3. code(where is it declared, or is it a standard thing?)<br>
: <br>
: where did you learned this stuff??<br>
: <br>
: with a book? the web?? pleas tell me!<br>
: <br>
: now I promise i wont send any more messages! :)<br>
: <br>
: <br>
: : I got it now!<br>
: : <br>
: : What you need to do is use WM_NOTIFY (Which of course is sent to the parent of the control ) and look for TVN_SELCHANGED.<br>
: : <br>
: : For example, say you have IDC_TREE1 on CMyDlg, you would do:<br>
: : <br>
: : BOOL CMyDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) <br>
: : {<br>
: : LPNM_TREEVIEW p = (LPNM_TREEVIEW) lParam;<br>
: : if( wParam == IDC_TREE1 && p->hdr.code == TVN_SELCHANGED )<br>
: : {<br>
: : // p->itemNew.hItem holds the handle of the new item to be selected.<br>
: : <br>
: : // we want to show the text in a message box, so<br>
: : CHAR szBuffer[ 1024 ];<br>
: : <br>
: : TV_ITEM Item;<br>
: : ZeroMemory( &Item, sizeof( Item ) );<br>
: : Item.mask = TVIF_TEXT;<br>
: : Item.hItem = p->itemNew.hItem;<br>
: : Item.pszText = szBuffer;<br>
: : Item.cchTextMax = sizeof( szBuffer );<br>
: : m_MyTree.GetItem( &Item );<br>
: : AfxMessageBox( szBuffer );<br>
: : }<br>
: : <br>
: : return CDialog::OnNotify(wParam, lParam, pResult);<br>
: : }<br>
: : <br>
: : <br>
: : : KMS<br>
: : : <br>
: : : I don't know how to erite the code right!<br>
: : : If I click one time on TreCtrl and the choose NM_CLICK<br>
: : : in a pop domn menu, then I can edit the code for<br>
: : : clicking the TREE control, not the items.... how to do so it<br>
: : : knows it is an item thats was clicked.<br>
: : : <br>
: : : hope that will work..... :)<br>
: : : <br>
: : <br>
: : <br>
: : <br>
: <br>
: <br>
: <br>
<br>






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.