CTreeCtrl 常用操作整理


属性设置:

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();



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值