m_treeImageList.Create(13, 13, FALSE, 3, 0);
     HICON hIcon = ::LoadIcon(AfxGetResourceHandle(),
          MAKEINTRESOURCE(IDI_ICON3));
     m_treeImageList.Add(hIcon);
     hIcon = ::LoadIcon(AfxGetResourceHandle(),
          MAKEINTRESOURCE(IDI_ICON4));
     m_treeImageList.Add(hIcon);
     hIcon = ::LoadIcon(AfxGetResourceHandle(),
          MAKEINTRESOURCE(IDI_ICON5));
     m_treeImageList.Add(hIcon);
     // Create the Tree View control.
     m_treeView.Create(WS_VISIBLE | WS_CHILD | WS_BORDER |
          TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS |
          TVS_EDITLABELS, CRect(20, 260, 160, 360), this,
          IDC_TREEVIEW);
     m_treeView.SetImageList(&m_treeImageList, TVSIL_NORMAL);
     // Create the root item.
     TV_ITEM tvItem;
     tvItem.mask =
          TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
     tvItem.pszText = "Root";
     tvItem.cchTextMax = 4;
     tvItem.iImage = 0;
     tvItem.iSelectedImage = 0;
     TV_INSERTSTRUCT tvInsert;
     tvInsert.hParent = TVI_ROOT;
     tvInsert.hInsertAfter = TVI_FIRST;
     tvInsert.item = tvItem;
     HTREEITEM hRoot = m_treeView.InsertItem(&tvInsert);
     // Create the first child item.
     tvItem.pszText = "Child Item 1";
     tvItem.cchTextMax = 12;
     tvItem.iImage = 1;
     tvItem.iSelectedImage = 1;
     tvInsert.hParent = hRoot;
     tvInsert.hInsertAfter = TVI_FIRST;
     tvInsert.item = tvItem;
     HTREEITEM hChildItem = m_treeView.InsertItem(&tvInsert);
     // Create a child of the first child item.
     tvItem.pszText = "Child Item 2";
     tvItem.cchTextMax = 12;
     tvItem.iImage = 2;
     tvItem.iSelectedImage = 2;
     tvInsert.hParent = hChildItem;
     tvInsert.hInsertAfter = TVI_FIRST;
     tvInsert.item = tvItem;
     m_treeView.InsertItem(&tvInsert);
     // Create another child of the root item.
     tvItem.pszText = "Child Item 3";
     tvItem.cchTextMax = 12;
     tvItem.iImage = 1;
     tvItem.iSelectedImage = 1;
     tvInsert.hParent = hRoot;
     tvInsert.hInsertAfter = TVI_LAST;
     tvInsert.item = tvItem;
     m_treeView.InsertItem(&tvInsert);
没时间看你的代码了还是你看一下我的吧

解决方案 »

  1.   

    m_treeImageList.Create(13, 13, FALSE, 3, 0);
         HICON hIcon = ::LoadIcon(AfxGetResourceHandle(),
              MAKEINTRESOURCE(IDI_ICON3));
         m_treeImageList.Add(hIcon);
         hIcon = ::LoadIcon(AfxGetResourceHandle(),
              MAKEINTRESOURCE(IDI_ICON4));
         m_treeImageList.Add(hIcon);
         hIcon = ::LoadIcon(AfxGetResourceHandle(),
              MAKEINTRESOURCE(IDI_ICON5));
         m_treeImageList.Add(hIcon);
         // Create the Tree View control.
         m_treeView.Create(WS_VISIBLE | WS_CHILD | WS_BORDER |
              TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS |
              TVS_EDITLABELS, CRect(20, 260, 160, 360), this,
              IDC_TREEVIEW);
         m_treeView.SetImageList(&m_treeImageList, TVSIL_NORMAL);
         // Create the root item.
         TV_ITEM tvItem;
         tvItem.mask =
              TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
         tvItem.pszText = "Root";
         tvItem.cchTextMax = 4;
         tvItem.iImage = 0;
         tvItem.iSelectedImage = 0;
         TV_INSERTSTRUCT tvInsert;
         tvInsert.hParent = TVI_ROOT;
         tvInsert.hInsertAfter = TVI_FIRST;
         tvInsert.item = tvItem;
         HTREEITEM hRoot = m_treeView.InsertItem(&tvInsert);
         // Create the first child item.
         tvItem.pszText = "Child Item 1";
         tvItem.cchTextMax = 12;
         tvItem.iImage = 1;
         tvItem.iSelectedImage = 1;
         tvInsert.hParent = hRoot;
         tvInsert.hInsertAfter = TVI_FIRST;
         tvInsert.item = tvItem;
         HTREEITEM hChildItem = m_treeView.InsertItem(&tvInsert);
         // Create a child of the first child item.
         tvItem.pszText = "Child Item 2";
         tvItem.cchTextMax = 12;
         tvItem.iImage = 2;
         tvItem.iSelectedImage = 2;
         tvInsert.hParent = hChildItem;
         tvInsert.hInsertAfter = TVI_FIRST;
         tvInsert.item = tvItem;
         m_treeView.InsertItem(&tvInsert);
         // Create another child of the root item.
         tvItem.pszText = "Child Item 3";
         tvItem.cchTextMax = 12;
         tvItem.iImage = 1;
         tvItem.iSelectedImage = 1;
         tvInsert.hParent = hRoot;
         tvInsert.hInsertAfter = TVI_LAST;
         tvInsert.item = tvItem;
         m_treeView.InsertItem(&tvInsert);
    没时间看你的代码了还是你看一下我的吧
      

  2.   

    1、tvi.item.iSelectedImage=2;下标应该是从0 开始的。
    2、delete pImageList;
    你把这个给Delete 了,系统从哪儿去找图标呀。