help: mfc treeview

holycow

Senior member
Feb 28, 2001
330
0
0
hi,

how do i bind treeview's control notification to an event handler in visual studio .net? i tried to bind TVN_SELCHANGED with an event handler.. i select the class that i want to add the event handler in 'class view' by right click on the chosen class, but the pop menu doesn't have the 'add event handler' command.. thx in advance..
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Not using the .Net I was able to double click on the Tree control within a dialog box and the wizard added the event handler for me.

Below is the code that was added to the CPP file.


BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_NOTIFY(NM_CLICK, IDC_TREE1, OnClickTree1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


void CAboutDlg:: OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here

*pResult = 0;
}
 

holycow

Senior member
Feb 28, 2001
330
0
0
i didn't use dialog or anything like that.. i just coded the codes for treeview in the initialupdate().. is there any otherway to add the control notification and the event handler without knowing the tree control id? thx.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
IF you are creating the object from scratch, you should have an ID assigned to it.
Just substitute the ID for where IDC_TREE1 is in my example in your message map area.
Add in your handler prototype as demonstrated
Define the handler prototype in the header file.


or

Create a dummy dialog or use the default About.
Add the Tree control using the wizards.
OBserve what changes are made to the related files.
Make the similar type of changes to your target files.