Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Advice and such for CTreeCtrl abstraction

BriballBriball Posts: 265Member
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.

Comments

  • weiccoweicco Posts: 950Member
    : 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:) ---

    [code]
    // 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);
    [/code]
Sign In or Register to comment.