ProgJ
2016-02-15 08:16
采纳率: 88.1%
浏览 2.1k

mfc 树形结构如何去掉默认选中?

 void TreeView::OnInitialUpdate()
{
    CTreeView::OnInitialUpdate();
    TVINSERTSTRUCT ti = { 0 };
    HTREEITEM hParent, Parent;
    ptheTree = &GetTreeCtrl();
    ptheTree->ModifyStyle(0, TVS_HASLINES | TVS_EDITLABELS);
    //TreeView* m_pMyView = (TreeView*)m_wndSplitter.GetPane(0, 0);
    HIMAGELIST himl;   //加入图标  
    himl = ImageList_Create(27, 27, ILC_COLOR24, 1, 12);
    ImageList_Add(himl, LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_BITMAP10)), NULL);
    SendMessage(TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)himl);

    ti.item.mask = TVIF_TEXT | TCIF_IMAGE | TVIF_SELECTEDIMAGE;
    ti.item.iImage = 2;
    ti.item.iSelectedImage = 2;
    ti.item.pszText = _T("默认文件夹");
    ti.hParent = NULL;
    ti.hInsertAfter = TVI_ROOT;

    Parent = hParent = (HTREEITEM)SendMessage(TVM_INSERTITEM, 0, (LPARAM)&ti);

    ti.hParent = hParent;
    ti.hInsertAfter = TVI_LAST;//TVI_LAST表示节点添加在最后  
    ti.item.iImage = 0;
    ti.item.iSelectedImage = 0;
    ti.item.pszText = _T("默认笔记本");
    hParent = (HTREEITEM)SendMessage(TVM_INSERTITEM, 0, (LPARAM)&ti);

    ti.item.iImage = 3;
    ti.item.iSelectedImage = 3;
    ti.item.pszText = _T("回收站");
    ti.hParent = NULL;
    ti.hInsertAfter = TVI_ROOT;
    Parent = hParent = (HTREEITEM)SendMessage(TVM_INSERTITEM, 0, (LPARAM)&ti);

    // TODO:  在此添加专用代码和/或调用基类
}

是哪里初始化的不对吗?
我试过在初始化里放SelectItem(NULL);没有用。。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • blownewbee 2016-02-15 23:49
    已采纳
      CTreeCtrl::SetItemState(lhItem, 0, TVIS_SELECTED);
    
    点赞 评论
  • blownewbee 2016-02-15 23:49

    lhItem为你要去掉的item的句柄

    点赞 评论

相关推荐 更多相似问题