属性设置:
Has Buttons :TRUE (Displays plus (+) and minus (-) buttons next to parent items.)
Has Lines: TRUE (Uses lines to show the hierarchy of items.)
Lines At Root:TRUE(Uses lines to link items at the root of the tree view control.)
函数:
HTREEITEM hParent = m_treePros.InsertItem(strMonitorText,0,0);
HTREEITEM hChild= m_treePros.InsertItem(strMonitorText,hTreeItem, TVI_LAST);
响应范例:
、、、、、、以右键单击为范例(其他鼠标操作类似)、、、、、、、、、、、、、、、、、、、、
void CDlgVideoPros::OnNMRClickTreePros(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code here
//右键 单击
CPoint pt;
UINT nFlags;
::GetCursorPos(&pt);
::ScreenToClient(m_treePros.m_hWnd, &pt);
HTREEITEM hItem = m_treePros.HitTest(pt,&nFlags);
if (hItem != 0 && (TVHT_ONITEM & nFlags))
{
if(m_treePros.SelectItem(hItem))
{
DWORD pItemData = m_treePros.GetItemData(hItem);
HTREEITEM hParentItem = m_treePros.GetParentItem(hItem);
if (hParentItem)
{
//第2层 监控设备
CMonitorDevice* pDevice = (CMonitorDevice*)pItemData;
CMenu Menu;
Menu.CreatePopupMenu();
//如果监控线程已经启动
if (pDevice->m_bConnectFlag)
{
Menu.AppendMenu(MF_STRING,ID_MENU_DISCONNECT_DEVICE, _T("断开链接"));
}else
{
Menu.AppendMenu(MF_STRING,ID_MENU_CONNECT_DEVICE, _T("开始链接"));
}
CPoint pt;
::GetCursorPos(&pt);
Menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, this);
}else
{
//第1层 监控点
CMonitorPoint* pMonitorPoint = (CMonitorPoint*)pItemData;
CMenu Menu;
Menu.CreatePopupMenu();
//如果监控线程已经启动
if (pMonitorPoint->m_bRunFlag)
{
Menu.AppendMenu(MF_STRING,ID_MENU_CLOSELOCALPORT, _T("停止监控"));
}else
{
Menu.AppendMenu(MF_STRING,ID_MENU_OPENLOCALPORT, _T("启动监控"));
}
CPoint pt;
::GetCursorPos(&pt);
Menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, this);
}
}
}
else
{
CMenu Menu;
Menu.CreatePopupMenu();
Menu.AppendMenu(MF_STRING,ID_MENU_ADDLOCALPORT, _T("添加新的监控点"));//添加新的监控点
CPoint pt;
::GetCursorPos(&pt);
Menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, this);
}
*pResult = 0;
}
菜单响应提示:
、、、、、、、、、、、、、、、、、、、、、、、、、、
ON_COMMAND(ID_MENU_ADDLOCALPORT,OnAddLocalPort)
void CDlgVideoPros::OnAddLocalPort();