C++ MFC

Moderators: Lundin
Number of threads: 3337
Number of posts: 9005

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Advice and such for CTreeCtrl abstraction Posted by Briball on 16 Feb 2004 at 1:11 PM
Here's my scenario. I'm displaying the contents of the windows computer's directories in a CTreeCtrl. Ok, fine easy. There are certain things that I need that cannot be stored in CTreeCtrl. I need a model that holds the data externally. Enters CDirNode.

Ok, first question. Right now CDirNode is in a linked list. This list is traversed VERY often. You think there'll be a big boost in speed if I implement a binary search tree instead (based on the values of HTREEITEM member)?

Second, the only problem I can't figure out is with CTreeCtrl's check boxes. Previously I processed the NM_CLICK notification and checked to see which boxes were checked. It would REALLY be nice to have a notification just when the user checks that damn box. Is there something like that? I checked and the docs didn't say much about notifications for change of state of item, which I know are present in other controls.
Report
Re: Advice and such for CTreeCtrl abstraction Posted by weicco on 17 Feb 2004 at 11:55 PM
: Here's my scenario. I'm displaying the contents of the windows computer's directories in a CTreeCtrl. Ok, fine easy. There are certain things that I need that cannot be stored in CTreeCtrl. I need a model that holds the data externally. Enters CDirNode.
:

But you can store data to CTreeCtrl nodes. See function CTreeCtrl::SetItemData. You could do something like this (or am I totally missing some point:) ---

// We store this kinds of structures to tree
struct MyStruct {
    MyStruct(CString& Name, DWORD dwOrder) {
        m_Name = Name;
        m_Order = dwOrder;
    };
    CString m_Name;
    DWORD m_Order;
};

CTreeCtrl m_MyTree;
HTREEITEM hItem = NULL;

// Let's create couple of nodes to tree
hItem = m_MyTree.InsertItem("Foo", NULL, NULL);
m_MyTree.SetItemData(hItem, (DWORD)new MyStruct("Foo", 1));
hItem = m_MyTree.InsertItem("Bar", hItem, NULL);
m_MyTree.SetItemData(hItem, (DWORD)new MyStruct("Bar", 1));

// Now we want to retrieve our structures
hItem = m_MyTree.GetRootItem();
MyStruct *pMyStruct1 = (MyStruct *)m_MyTree.GetItemData(hItem);
hItem = m_MyTree.GetChildItem(hItem);
MyStruct *pMyStruct2 = (MyStruct *)m_MyTree.GetItemData(hItem);




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.