Advice and such for CTreeCtrl abstraction - Programmers Heaven

Howdy, Stranger!

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

Categories

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.