请大家帮忙,先谢过了~~~~目的:当点击子节点,可以同时获取子节点及其父节点的名称。void CDlgContext::OnSelchangedTreeContext(NMHDR* pNMHDR, LRESULT* pResult) 
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CTreeCtrl* m_ptree = (CTreeCtrl*)GetDlgItem(IDC_TREE_CONTEXT);
HTREEITEM item;
CString strChild, strParent;
strChild = m_ptree->GetItemText(pNMTreeView->itemNew.hItem); //这里获取子节点名称
GetDlgItem(IDC_EDIT1)->SetWindowText(strChild); UpdateData(FALSE); *pResult = 0;
}但是,实在不知道如何获取它的父节点名称

解决方案 »

  1.   

    先获取父节点的句柄,用CTreeCtrl::GetParentItem获取
    然后就可以根据句柄获取名称了
      

  2.   


    HTREEITEM hParentItem;//父节点
    HTREEITEM hChildItem;//子节点
    CTreeCtrl* pmyTreeCtrl;//这个最好定义为成员变量,在.h文件中定义
    hParentItem = pmyTreeCtrl->GetParentItem(hChildItem);//获取父节点句柄
    CString Parent = pmyTreeCtrl->GetItemText(hParentItem);//Returns the text of the item specified by hItem.我没测试,你自己试试,应该可以的
      

  3.   


    麻烦你了,我想再问个关于SQL的问题。_bstr_t        vSQL;
    vSQL = "select DD_Name, DD_Another, DD_Description, DD_MakeUp, DD_Location from " + strParent + "where DD_Name = " + "'" + strChild + "'";
    //我知道是 单引号那里出了问题,可就是不知道怎么改
      

  4.   


    vSQL = "select DD_Name, DD_Another, DD_Description, DD_MakeUp, DD_Location from " + strParent + " where DD_Name = " + "'" + strChild + "'";where 前要有空格,另外还要将strChild中的单引号换成两个单引号,否则会出错
    建议不要这样拼接字符串,可以使用sprintf之类的作为辅助
      

  5.   


    这次真搞定了!谢谢啊~~
    where 前面竟然少打了一个空格,太粗心了!