ctreectrl problem

Posted on 2004-11-10
Last Modified: 2013-11-20
Hi! Here's a picture of my application <>. As you can see its a simple ctreectrl inside a ctabctrl which is also inside a cformsview. I have overridden the OnSize of my MainFrm so that I can resize the views, tabs, tree properly. My problem is, when I select an item from the tree and then minimize it, upon restoring the window my tree gets screwed up. Here's a picture <>. Here's part of my source code:


#pragma once
class CMainFrame : public CFrameWnd
protected: // create from serialization only

// Attributes

// Operations

// Overrides
      virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    virtual BOOL OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext *pContext );

// Implementation
      virtual ~CMainFrame();
#ifdef _DEBUG
      virtual void AssertValid() const;
      virtual void Dump(CDumpContext& dc) const;

protected:  // control bar embedded members
      CStatusBar  m_wndStatusBar;
      CToolBar    m_wndToolBar;
    CSplitterWnd m_wndMainSplitter;
    CSplitterWnd m_wndChildSplitter;

    CModuleView *m_wndModView;
    COgreView *m_wndOgreView;
    CObjectsView *m_wndObjectsView;
    CMessagesView *m_wndMessagesView;

// Generated message map functions
    afx_msg void OnSize( UINT nType, int cx, int cy );
      afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

Here's only part of MainFrm.cpp which I think is relevant:
// CMainFrame message handlers
afx_msg void CMainFrame::OnSize( UINT nType, int cx, int cy )
    CFrameWnd::OnSize( nType, cx, cy );
    //resize splitter panes here
    if( (splitterInit && nType != SIZE_MINIMIZED) ||
        (splitterInit && nType == SIZE_RESTORED) ) {
        m_wndMainSplitter.SetRowInfo( 0, cy-150, 50 );

        m_wndChildSplitter.SetColumnInfo( 0, 200, 50 );
        m_wndChildSplitter.SetColumnInfo( 1, cx-400, 50 );
        m_wndChildSplitter.SetColumnInfo( 2, 200, 50 );
        //resize tab on right with tree properly
        int width = 0;
        int height = 0;
        int tempIdeal = 0;

        m_wndMainSplitter.GetRowInfo( 0, height, tempIdeal );
        m_wndChildSplitter.GetColumnInfo( 2, width, tempIdeal );        
        m_wndObjectsView->m_wndTab.MoveWindow( 0, 50, width, height-50 );
        m_wndObjectsView->m_wndTree.MoveWindow( 5, 80, width-10, height-90 );            

As for the CFormView which holds the tree, I have overridden the OnInitialUpdate function:
void CObjectsView::OnInitialUpdate()
    //add stuff to the tree

I have already tried calling the Invalidate(), RedrawWindow(), and UpdateWindow() methods of the tree. But it still doesn't display itself when an item is selected, the window minimized, and restored.

If you want to view the entire project, you can get it at <>. Its 600kb. Sorry for the hassle. I would really appreciate it if you could check it out.

If you can't figure this out, maybe you could at least tell me how to clear a tree. I've tried:


After calling this method, I can no longer attach any items to the tree. For example,

m_wndTree.InsertItem( "helloworld", TVI_ROOT, TVI_LAST );

helloworld doesn't appear in the tree. What am I missing here?

Thanks so much!
Question by:paulr1984
    LVL 13

    Expert Comment

    Are you repainting the tree ctrl when the application gets restored?
    LVL 13

    Expert Comment

    The view needs to check the tree selection and draw the tree content accordingly. I am missing this function in your code.

    And it seems strange that the tab control spin is changing the position of tabs. It should just make other visible.
    LVL 30

    Accepted Solution

    Hi paulr1984,

    the re-draw problem seems to be simply a z-order problem: the tree-ctrl is drawn befor the tab-ctrl.

    I just swapped the order of these in the dialog-resource, then it's re-drawn correctly ...

    The other problem seems to be just a graphical problem ... If you re-size the mainframe after the DeleteAllItems() the new added items re-appear ... unfortunateley I have to leave my office now, but I'll try to continue bug-search tomorrow morning ...

    hope that helps,


    Author Comment

    Your right zoppo.  Thanks.  But i already found the answer in my other post

    I'm trying to save as much points as I can.  I'm forseeing several more spikes which can come up in my project.  Sorry Zoppo but I'll have to refund my points.  How do I do this again?
    LVL 30

    Expert Comment

    hm ... would have really been a good idea to tell us here there's no more need waste any time for nothing ...

    Ask a question in community support if you want to refund the points ...

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Decoding 32 bit binary streams 6 20
    paragon account problem 9 88
    Doc'in system (example?) BA 7 64
    FizzBuzz challenge 9 65
    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now