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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. TreeCtrl Navigating all items programatically

TreeCtrl Navigating all items programatically

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresperformancetutorialquestion
7 Posts 3 Posters 0 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.
  • V Offline
    V Offline
    Vikash Dubey 0
    wrote on last edited by
    #1

    ;PHello all, I am using CTreeCtrl and when creating items and I am storing a LPSTR into the lParam of the TVITEM struct. When I need to clear the contents I need to free the memory allocated but to get the pointers I need to traverse all items in the tree ctrl but could not find any easy way to do it. Can anyone guide me? Will the method that i write be recursive or can i write a non recursive function? I need to get each item data in the tree and then free the memory and then I can call DeleteAllItems on the tree. Thank you Memory Leaks are very dangerous.;P

    M 1 Reply Last reply
    0
    • V Vikash Dubey 0

      ;PHello all, I am using CTreeCtrl and when creating items and I am storing a LPSTR into the lParam of the TVITEM struct. When I need to clear the contents I need to free the memory allocated but to get the pointers I need to traverse all items in the tree ctrl but could not find any easy way to do it. Can anyone guide me? Will the method that i write be recursive or can i write a non recursive function? I need to get each item data in the tree and then free the memory and then I can call DeleteAllItems on the tree. Thank you Memory Leaks are very dangerous.;P

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      It's nowhere near as complicated as that. Handle the TVN_DELETEITEM notification to know when an item is being deleted. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Pinky, are you pondering what I'm pondering? I think so Brain, but how will we fit the hamster inside the accordion?

      P V 2 Replies Last reply
      0
      • M Michael Dunn

        It's nowhere near as complicated as that. Handle the TVN_DELETEITEM notification to know when an item is being deleted. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Pinky, are you pondering what I'm pondering? I think so Brain, but how will we fit the hamster inside the accordion?

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        Micheal, If the treeitem contains child notes that has allocated memory for lparam, will i get notification for each childitem when i delete its parent item. My God is more powerfull Than Your God. (the line that divides the world)

        M 1 Reply Last reply
        0
        • M Michael Dunn

          It's nowhere near as complicated as that. Handle the TVN_DELETEITEM notification to know when an item is being deleted. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Pinky, are you pondering what I'm pondering? I think so Brain, but how will we fit the hamster inside the accordion?

          V Offline
          V Offline
          Vikash Dubey 0
          wrote on last edited by
          #4

          Thank you very much Mike works very well. I have read your articles on this site and find them very good. I admire you. Thanks once again. But one more question I am using a ActiveX control and allocating it on the heap. I create it by calling Create(). When i free the memory the GDI object handles and USER object shown in process viewer decreases but not to the count it was before I do the creation operation If i try to call DestroyWindow() it gives assertion error. Why is it so? What should i do to decrease the GDI object and USER object count as it increases with usage time.

          M 1 Reply Last reply
          0
          • P Prakash Nadar

            Micheal, If the treeitem contains child notes that has allocated memory for lparam, will i get notification for each childitem when i delete its parent item. My God is more powerfull Than Your God. (the line that divides the world)

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Yes, you get a notification for every item that gets deleted from the tree. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.   -- Michael P. Butler in the Lounge

            P 1 Reply Last reply
            0
            • V Vikash Dubey 0

              Thank you very much Mike works very well. I have read your articles on this site and find them very good. I admire you. Thanks once again. But one more question I am using a ActiveX control and allocating it on the heap. I create it by calling Create(). When i free the memory the GDI object handles and USER object shown in process viewer decreases but not to the count it was before I do the creation operation If i try to call DestroyWindow() it gives assertion error. Why is it so? What should i do to decrease the GDI object and USER object count as it increases with usage time.

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #6

              The most common mistake is forgetting to select pens/bitmaps/etc. out of a device context. For ex. if you do this (pseudo-MFC code here, since I'm in a hurry ;) )

              CPen p (RGB(255,0,0));

              dc.SelectObject(p);
              dc.MoveTo(0,0);
              dc.LineTo(100,100);

              p.DeleteObject();

              the pen will not be deleted because it's still the active pen in a DC. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber You cannot truly appreciate Dilbert unless you've read it in the original Klingon.

              1 Reply Last reply
              0
              • M Michael Dunn

                Yes, you get a notification for every item that gets deleted from the tree. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.   -- Michael P. Butler in the Lounge

                P Offline
                P Offline
                Prakash Nadar
                wrote on last edited by
                #7

                Wow, Thanx again micheal, this method replaced my (quite complex) recurrsive way of deleteing the child items :-) My God is more powerfull Than Your God. (the line that divides the world)

                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