16,471
社区成员
发帖
与我相关
我的任务
分享
一.插入值(三层):
HTREEITEM TopItem;
HTREEITEM SubItem;
CTreeCtrl m_ctrlModelTree;
for (int n=0; n<i; n++)
{
//插入根结点,同时得到根结点指针插入后指针会自动移动到下一位置
TopItem = m_ctrlModelTree.InsertItem(strEquip[n][1]);
for (m=0; m<j; m++)
{
//插入第一层结点
SubItem = m_ctrlModelTree.InsertItem(strHander[m][1],0,0,TopItem);
for (int p=0; p<k; p++)
{
//插入第二层结点
m_ctrlModelTree.InsertItem(strModel[p][0],0,0,SubItem);
........
}
}
}
二.响应鼠标右击事件:
//控件加右击事件
void CPaperCreateDlg::OnRClickTreeModelman(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CString strCheck=_T("");
HTREEITEM CheckIndex = NULL;
HTREEITEM ParentIndex=NULL;
CString strPapername;
//右键所在结点项
CheckIndex = m_ctrlModelTree.GetDropHilightItem();
strPapername = m_ctrlModelTree.GetItemText(CheckIndex);
//AfxMessageBox(strPapername);
ParentIndex = m_ctrlModelTree.GetParentItem(CheckIndex);
CString mParentItem = m_ctrlModelTree.GetItemText(ParentIndex);
//点中根结点
if (mParentItem!="")
{
//试卷名
mDelPaperName = strPapername;
CPoint mClientPos;
GetCursorPos(&mClientPos);
CPoint mPoint =mClientPos;
//将客户区坐标转换成屏幕坐标
//ClientToScreen(&mPoint);
CMenu mMenu;
mMenu.LoadMenu(IDR_DELPAPER);
CMenu* pPopup = mMenu.GetSubMenu(0);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, (mPoint.x+5),
(mPoint.y+8),this);
}
*pResult = 0;
}