Solved

Windows trees

Posted on 1998-08-04
1
228 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 113
Looking for a specific application/software 2 104
sumNumber challenge 16 112
either24  challenge 19 90
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…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now