Solved

Windows trees

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

12 Experts available now in Live!

Get 1:1 Help Now