Solved

Windows trees

Posted on 1998-08-04
1
230 Views
Last Modified: 2013-11-19
Dear experts,
How do you get the tree function to behave like a normal windows tree function..
When you use this code the icons show as an open folder only when you select them and they dont stay open as you continue down the tree?
I want this tree to behave as a normal windows explorer tree.. that is the icons will show as folder open as you traverse down the tree and will close as you come back up the tree.
(Also for the images
image 0 = folder closed
image 1 = floder closed
image 2 = folder open)

The current code..(this is for use in a dialog box)


    // Create the Image List.
      m_treeImageList.Create(13, 13, FALSE, 3, 0);
      HICON hIcon = ::LoadIcon(AfxGetResourceHandle(),
            MAKEINTRESOURCE(IDI_ICON1));//CHANGE your Icons here
      m_treeImageList.Add(hIcon);
      hIcon = ::LoadIcon(AfxGetResourceHandle(),
            MAKEINTRESOURCE(IDI_ICON1));//CHANGE your Icons here
      m_treeImageList.Add(hIcon);
      hIcon = ::LoadIcon(AfxGetResourceHandle(),
            MAKEINTRESOURCE(IDI_ICON2));//CHANGE your Icons here
      m_treeImageList.Add(hIcon);

    m_treeView.SetImageList(&m_treeImageList, TVSIL_NORMAL);//this is optional

      // Create the root item.
      TV_ITEM tvItem;
      tvItem.mask =
            TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
      tvItem.pszText = "Root";
      tvItem.cchTextMax = 4;
      tvItem.iImage = 1;
      tvItem.iSelectedImage = 2;
      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 = 2;
      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 = 1;
      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 = 2;
      tvInsert.hParent = hRoot;
      tvInsert.hInsertAfter = TVI_LAST;
      tvInsert.item = tvItem;
      m_treeView.InsertItem(&tvInsert);
0
Comment
Question by:Soth
1 Comment
 
LVL 1

Accepted Solution

by:
Andy_Keys earned 100 total points
ID: 1320271
Look at changing the icon when you get an Exanding or expanded messaage. ie when you get the expandeding use (TVE_EXPAND == pNMTreeView->action) to see if its expanding or collasping and change the icon accordinlg
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 121
Turn a spreadsheet into a vba executable. 2 85
not able to insert into temp table 68 162
tripleUp challenge 7 78
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question