Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Tree Control

Tree Control

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
10 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Syamlal S Nair
    wrote on last edited by
    #1

    How to send a message to a tree control to select an item inside it( I have the handle to the tree view in my hands)?

    SYAMLAL

    F 1 Reply Last reply
    0
    • S Syamlal S Nair

      How to send a message to a tree control to select an item inside it( I have the handle to the tree view in my hands)?

      SYAMLAL

      F Offline
      F Offline
      Frank K
      wrote on last edited by
      #2

      Hi,

      SendMessage(hWndTreeView, TVM_SELECTITEM, ActionFlag, hTreeItem);
      

      TVM_.... -> TreeViewMessage HTH

      S 1 Reply Last reply
      0
      • F Frank K

        Hi,

        SendMessage(hWndTreeView, TVM_SELECTITEM, ActionFlag, hTreeItem);
        

        TVM_.... -> TreeViewMessage HTH

        S Offline
        S Offline
        Syamlal S Nair
        wrote on last edited by
        #3

        Hi Frank I know the prototype of send message,,,But can U explain the 4th parameter in particular.. What I am trying to do is: To automate a local ghosting tool The tool is having a window upon which the treeview resides Items in tree view: Harddisk DellUtility C: D: All these are selected by default I want to select the C: only,,and that I have to do from the code I have the handle to the tree view(Obtained using EnumChildWindows()) I think two ways of sending message is there: 1)Get handle to the item"C:" of type HTREEITEM and send a mouse click message 2)Get handle to the item "C:" of type HTREEITEM and send a select message But how to do it?????I tried in different ways ,,but no hope.... Pls help me,,,,

        SYAMLAL

        P 1 Reply Last reply
        0
        • S Syamlal S Nair

          Hi Frank I know the prototype of send message,,,But can U explain the 4th parameter in particular.. What I am trying to do is: To automate a local ghosting tool The tool is having a window upon which the treeview resides Items in tree view: Harddisk DellUtility C: D: All these are selected by default I want to select the C: only,,and that I have to do from the code I have the handle to the tree view(Obtained using EnumChildWindows()) I think two ways of sending message is there: 1)Get handle to the item"C:" of type HTREEITEM and send a mouse click message 2)Get handle to the item "C:" of type HTREEITEM and send a select message But how to do it?????I tried in different ways ,,but no hope.... Pls help me,,,,

          SYAMLAL

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #4

          SyamlalS wrote:

          ,,,But can U explain the 4th parameter in particular..

          Its handle to tree item. Its can be obtained using any of CTreeCtrl functions(GetNextItem,GetChildItem etc,).

          Prasad Notifier using ATL | Operator new[],delete[][^]

          S 1 Reply Last reply
          0
          • P prasad_som

            SyamlalS wrote:

            ,,,But can U explain the 4th parameter in particular..

            Its handle to tree item. Its can be obtained using any of CTreeCtrl functions(GetNextItem,GetChildItem etc,).

            Prasad Notifier using ATL | Operator new[],delete[][^]

            S Offline
            S Offline
            Syamlal S Nair
            wrote on last edited by
            #5

            Even GETITEM,GETNEXTITEM etc requires a TVITEM parameter, which again contains a handle to tree item(hItem field),So how can I get the first item??? If I get handle to the first item I can apply GETNEXTITEM and reach at the particular(C:)item... Pls do reply Thanx to Prasad_som and Frank K and all others who are willing to reply for showing interest in my request,,,,

            SYAMLAL

            P 1 Reply Last reply
            0
            • S Syamlal S Nair

              Even GETITEM,GETNEXTITEM etc requires a TVITEM parameter, which again contains a handle to tree item(hItem field),So how can I get the first item??? If I get handle to the first item I can apply GETNEXTITEM and reach at the particular(C:)item... Pls do reply Thanx to Prasad_som and Frank K and all others who are willing to reply for showing interest in my request,,,,

              SYAMLAL

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #6

              You already told in original post, that you have window handle, This snippet may help you to understand traversing tree control. It gets first child of root item and traverse its children.

              // find root
              HTREEITEM hRoot = pCtrl->GetRootItem();//pCtrl is CTreeCtrl pointer

              if (hRoot == NULL)
              MessageBox(_T("some problem"));
              else
              {
              }
              HTREEITEM hChild = pCtrl->GetNextItem(hRoot,TVGN_CHILD)
              if (pmyTreeCtrl->ItemHasChildren(hChild))
              {
              HTREEITEM hNextItem;
              HTREEITEM hChildItem = pmyTreeCtrl->GetChildItem(hmyItem);

              while (hChildItem != NULL)
              {
              hNextItem = pmyTreeCtrl->GetNextItem(hChildItem, TVGN_NEXT);
              hChildItem = hNextItem;
              }
              }

              Prasad Notifier using ATL | Operator new[],delete[][^]

              S 1 Reply Last reply
              0
              • P prasad_som

                You already told in original post, that you have window handle, This snippet may help you to understand traversing tree control. It gets first child of root item and traverse its children.

                // find root
                HTREEITEM hRoot = pCtrl->GetRootItem();//pCtrl is CTreeCtrl pointer

                if (hRoot == NULL)
                MessageBox(_T("some problem"));
                else
                {
                }
                HTREEITEM hChild = pCtrl->GetNextItem(hRoot,TVGN_CHILD)
                if (pmyTreeCtrl->ItemHasChildren(hChild))
                {
                HTREEITEM hNextItem;
                HTREEITEM hChildItem = pmyTreeCtrl->GetChildItem(hmyItem);

                while (hChildItem != NULL)
                {
                hNextItem = pmyTreeCtrl->GetNextItem(hChildItem, TVGN_NEXT);
                hChildItem = hNextItem;
                }
                }

                Prasad Notifier using ATL | Operator new[],delete[][^]

                S Offline
                S Offline
                Syamlal S Nair
                wrote on last edited by
                #7

                Dear Prasad,, I have the handle to the tree view and not a pointer So I can't invoke the GetRootItem function Expect ur reply..

                SYAMLAL

                P 1 Reply Last reply
                0
                • S Syamlal S Nair

                  Dear Prasad,, I have the handle to the tree view and not a pointer So I can't invoke the GetRootItem function Expect ur reply..

                  SYAMLAL

                  P Offline
                  P Offline
                  prasad_som
                  wrote on last edited by
                  #8

                  SyamlalS wrote:

                  I have the handle to the tree view and not a pointer

                  CTreeCtrl *pTreeCtrl = dynamic_cast<CTreeCtrl*> (CWnd::FromHandle(hWndYouHave));

                  Prasad Notifier using ATL | Operator new[],delete[][^]

                  S 1 Reply Last reply
                  0
                  • P prasad_som

                    SyamlalS wrote:

                    I have the handle to the tree view and not a pointer

                    CTreeCtrl *pTreeCtrl = dynamic_cast<CTreeCtrl*> (CWnd::FromHandle(hWndYouHave));

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    S Offline
                    S Offline
                    Syamlal S Nair
                    wrote on last edited by
                    #9

                    Thanx a lot ,,Prasad... dynamic cast was not required This is enough: CTreeCtrl* pCtrl = (CTreeCtrl*)(CWnd::FromHandle(HandleToTreeView)); NeWay thaks a lot again.....

                    SYAMLAL

                    P 1 Reply Last reply
                    0
                    • S Syamlal S Nair

                      Thanx a lot ,,Prasad... dynamic cast was not required This is enough: CTreeCtrl* pCtrl = (CTreeCtrl*)(CWnd::FromHandle(HandleToTreeView)); NeWay thaks a lot again.....

                      SYAMLAL

                      P Offline
                      P Offline
                      prasad_som
                      wrote on last edited by
                      #10

                      SyamlalS wrote:

                      dynamic cast was not required This is enough: CTreeCtrl* pCtrl = (CTreeCtrl*)(CWnd::FromHandle(HandleToTreeView));

                      This works, but C++ standard encourages using dynamic_cast or other operators(reinterpre_cast,static_cast) . And old function style casts should be avoided wherever possible.

                      Prasad Notifier using ATL | Operator new[],delete[][^]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups