CTreeCtrl

CTreeCtrl_第1张图片

1、插入 Tree Contr控件
在对话框的头文件中:
public:
CTreeCtrl m_OrgInfo;
CImageList m_ImageList;
afx_msg void OnEnChangeEdit1();
CEdit m_HAHA;
afx_msg void OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton2();


CBitmap  bm[100];
void SetTree(void);//很重要的设置树

2、函数实现
BOOL CMFCTreeIndexTestDlg::OnInitDialog()
{
SetTree();



CString node_name;
void CMFCTreeIndexTestDlg::OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);


// TODO: 在此添加控件通知处理程序代码
UpdateData(true);
node_name = m_OrgInfo.GetItemText(pNMTreeView->itemNew.hItem);
SetWindowText(node_name);
if (pNMTreeView->itemNew.hItem == root)
{
SetDlgItemText(IDC_EDIT1,L"xuxinxuxin ,nihao ,nihao");
}
else if(node_name == "small")
{
MessageBox(L"BBB");
}
UpdateData(false);

*pResult = 0;
}



void CMFCTreeIndexTestDlg::SetTree(void)
{
m_OrgInfo.ModifyStyle(NULL, TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
bm[0].LoadBitmap(IDB_BITMAP1);
bm[1].LoadBitmap(IDB_BITMAP2);
m_ImageList.Create(16,16,ILC_MASK,0,4);
m_ImageList.Add(&bm[0], (COLORREF)0xFFFFFF);
m_ImageList.Add(&bm[1], (COLORREF)0xFFFFFF);


m_OrgInfo.SetImageList(&m_ImageList, TVSIL_NORMAL);
root = m_OrgInfo.InsertItem(_T("root"),0,0);
int i,j;
for (i = 0; i < 4; i++)
{
HTREEITEM item = m_OrgInfo.InsertItem(_T("item"),1,1,root);
for (j = 0; j < 3; j++)
{
m_OrgInfo.InsertItem(_T("small"),0,1,item);
}
}
}

CTreeCtrl_第2张图片

你可能感兴趣的:(CTreeCtrl)