鼠标点击某个项,怎样获取它是属于第几级目录?以及它这级目录中排第几?
看了下资料,似乎只能获得选中项的文本,而不能获取它的位置信息?
看了下资料,似乎只能获得选中项的文本,而不能获取它的位置信息?
解决方案 »
- 如何让安装的字体立即生效?
- 如何在vc6.0下实现自动捕捉其他窗口的确定按钮?
- vc2008d对话框static edit控件中文不显示!
- vc6+omniORB写的CORBA程序传递一个字符串时,总是抱_CrtIsValidHeapPointer(pUserData)的错误,为什么?
- 高分请教 在COMBOBOX中如何更改 它下属 的 EDIT 的尺寸大小??
- 比较难的问题,谁能搞定,分大大的送上
- 请问 通过程序向EditView写文本????????
- 帮忙看两句代码的区别
- vs2010编译xvidcore中的libxvidcore成功,但是却没生成libxvidcore.lib
- 如何模拟点击窗体(TActionToolBar)中按钮?
- 怎样实现大光标
- 针对IE下载ActiveX控件时间太长(9M大小),怎样做一个友好界面?
void CXXXDlg::TraveTree(HTREEITEM hRoot, const HTREEITEM& hItem, int &nCount)
{
if(!hItem || !hRoot || hRoot == hItem)
{
return ;
}
HTREEITEM hChildItem;
HTREEITEM hNextItem;
nCount ++;
hChildItem = m_tree.GetChildItem(hRoot);
TraveTree(hChildItem, hItem, nCount); hNextItem = m_tree.GetNextSiblingItem(hRoot);
TraveTree(hNextItem, hItem, nCount);
}// 调用
HTREEITEM hItem = m_tree.GetSelectedItem();
if(hItem)
{
int nDir = 1;
int nCount = 1; HTREEITEM hNextItem = hItem;
while(NULL != (hNextItem = m_tree.GetParentItem(hNextItem)))
{
nDir++;
} TraveTree(m_tree.GetRootItem(), hItem, nCount);
CString strText(_T(""));
strText.Format(_T("目录级别:%d, 位置索引:%d"), nDir, nCount);
AfxMessageBox(strText);
}
这样的话,取的时候,也不需要递归了,GetItemData()
我最后没用获取位置的方式解决。方法有点傻,用的是判断选择ITEM的文字进行定位的void CPicTreeView::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
// TODO: Add your control notification handler code here
CTreeCtrl& CtlTree=(CTreeCtrl&)GetTreeCtrl(); //获得选项句柄
HTREEITEM select_htem=CtlTree.GetSelectedItem();
CString select_str=CtlTree.GetItemText(select_htem);
//获得父节点句柄
HTREEITEM parent_htem=CtlTree.GetParentItem(select_htem);
CString p_str=CtlTree.GetItemText(parent_htem); if (p_str==_T(""))
return; if (p_str==_T("影像匹配"))
{
if (select_str==_T("左片影像")&&!bLeft) //左片
{
bLeft=!bLeft;
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
CRect rect;
//获得该视图的大小
(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,1))->GetClientRect(rect);
pMainFrame->m_wndSplitter.ReplaceView(0,1,RUNTIME_CLASS(CLeftView),CSize(rect.Width(),rect.Height()),1,1,0);
return;
}
if (select_str==_T("右片影像")&&!bRight) //左片
{
bRight=!bRight;
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
CRect rect;
//获得该视图的大小
(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,2))->GetClientRect(rect);
pMainFrame->m_wndSplitter.ReplaceView(0,2,RUNTIME_CLASS(CRightView),CSize(rect.Width(),rect.Height()),1,2,0);
return; }
}
if (p_str==_T("左片影像"))
{
if (select_str==_T("特征点列表")&&bLeft)
{
bLeft=!bLeft;
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
CRect rect;
//获得该视图的大小
(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,1))->GetClientRect(rect);
pMainFrame->m_wndSplitter.ReplaceView(0,1,RUNTIME_CLASS(CLeftList),CSize(rect.Width(),rect.Height()),0,0,0);
return;
}
CPicMatchDoc *pDoc=((CPicTreeView*)(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,0)))->GetDocument();
for(int li=0;li<pDoc->nImgL;li++)
{
CString strl;
strl.Format(_T("第 %d 层"),li+1);
if (select_str==strl&&!bLeft) //左片
{
bLeft=!bLeft;
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
CRect rect;
//获得该视图的大小
(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,1))->GetClientRect(rect);
pMainFrame->m_wndSplitter.ReplaceView(0,1,RUNTIME_CLASS(CLeftView),CSize(rect.Width(),rect.Height()),1,1,pDoc->nImgL-1-li);
return;
}
CLeftView * pLView= (CLeftView*)(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,1));
if (select_str==strl&&bLeft&&pDoc->nImgL-1-li!=pLView->nLayer)
{
pLView->nLayer=pDoc->nImgL-1-li;
pLView->Invalidate(NULL);
return;
} }
}
if (p_str==_T("右片影像"))
{
if (select_str==_T("特征点列表")&&bRight)
{
bRight=!bRight;
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
CRect rect;
//获得该视图的大小
(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,2))->GetClientRect(rect);
pMainFrame->m_wndSplitter.ReplaceView(0,2,RUNTIME_CLASS(CRightList),CSize(rect.Width(),rect.Height()),0,0,0);
return;
}
CPicMatchDoc *pDoc=((CPicTreeView*)(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,0)))->GetDocument();
for(int li=0;li<pDoc->nImgR;li++)
{
CString strr;
strr.Format(_T("第 %d 层"),li+1);
if (select_str==strr&&!bRight) //左片
{
bRight=!bRight;
CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd();
CRect rect;
//获得该视图的大小
(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,2))->GetClientRect(rect);
pMainFrame->m_wndSplitter.ReplaceView(0,2,RUNTIME_CLASS(CRightView),CSize(rect.Width(),rect.Height()),1,2,pDoc->nImgR-1-li);
return;
} CRightView * pRView= (CRightView*)(((CMainFrame*)AfxGetMainWnd())-> m_wndSplitter.GetPane(0,2));
if (select_str==strr&&bLeft&&pDoc->nImgR-1-li!=pRView->nLayer)
{
pRView->nLayer=pDoc->nImgR-1-li;
pRView->Invalidate(NULL);
return;
} }
} *pResult = 0;
}
开始用的单击触发,GetSelectedItem()返回的是上一个的句柄。现在就剩最后一个问题了,你的这个索引值是怎么计算的?我希望得到的nCount是该目录下的重新一次排列的,每一级目录的子项都是从头排的,1,2,3,4....这样。
我先自己试一下吧,主要对递归的理解不够
不过有一种方法,就是不同的目录节点后面加上不同的符号区别。比如根目录节点文字后面加>>>,一级目录加>>,二级目录加>,子节点就什么都不加。处理的时候判断字符串来区别就行了。
不过还是visualeleven的方法科学。
可以确定第几级,根据父节点的ITEMTEXT判断。
一般同一级中需要相同文字的很少。上下级遇到相同文字是根据父节点的文字不同进行区分。当然,我这是第一次用TreeCtrl,所以很多函数不熟,考虑不是很周全。
就比如说根节点下有A、B、C三个节点,而A下又有A1,A2两个节点,当前选中B节点?要求得出的索引值为2??是这个意思???
比如说根节点下有A、B、C三个节点,而A下又有A1,A2两个节点,当前选中B节点?要求得出的索引值为2
----------------------------------------------------------------------------------
你要得到B的索引值,
你遍历的话,你要先得到该选择节点的父节点,B的父节点是根节点,那么你就要从根节点开始遍历,依次找到B,结束就得到了B的的索引值。如果你要得到A1的索引,那么同上,你要先得到A1的父节点A,然后从A节点开始遍历,找到A1,结束,得到A1
的索引值。这样应该很清楚了吧
还是上面的例子,你要得到C节点的索引,从根节点开始,遍历得到A,就不用遍历A的子节点了,即遍历兄弟节点即可