选中树节点事件:
//处理鼠标单击树形控件节点操作
void CTreeMFCDlg::OnTvnSelchangedMytree(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
CString StrPath;
CString StrInfo;
HTREEITEM CurItem=m_treeTest.GetSelectedItem();   /*选取选中节点*/
TV_ITEM TreeCtrlItem;                /*就是这个释放有问题*/
TreeCtrlItem.hItem=CurItem;
m_treeTest.GetItem(&TreeCtrlItem);
StrInfo=m_treeTest.GetItemText(m_treeTest.GetSelectedItem()); StrPath=StrInfo;
GetDlgItem(IDC_EDITINFO)->SetWindowText(StrPath); /*写入一个文本框中*/
*pResult = 0;
}执行完这个事件,就出现错误:Run-Time Check Failure #2 - Stack around the variable 'TreeCtrlItem' was corrupted.为什么会这样啊?

解决方案 »

  1.   


          TreeCtrlItem.mask  = TVIF_HANDLE;
          TreeCtrlItem.hItem = CurItem;
      

  2.   

    1楼 正解 
     一下TVITEM
    Specifies or receives attributes of a tree view item. This structure is identical to the TV_ITEM structure, but it has been renamed to follow current naming conventions. New applications should use this structure.
    typedef struct tagTVITEM{
        UINT      mask;
        HTREEITEM hItem;
        UINT      state;
        UINT      stateMask;
        LPTSTR    pszText;
        int       cchTextMax;
        int       iImage;
        int       iSelectedImage;
        int       cChildren;
        LPARAM    lParam;
    } TVITEM, FAR *LPTVITEM;