WTL : create CtreeViewCtrl On CPaneContainerImpl

窗口切分后, 每个窗口都作为一个CPaneContainer.

在其中一个CPaneContainer中建立一个TreeViewCtrl.

为了封装的更好, 将CPanContainer和CTreeViewCtrl进一步封装成类.

开始CMyTreeViewCtrl总是不能刷新, 一点一点的调试,

最后发现要点是: CTreeViewCtrl必须是一个以WC_TREEVIEW开始的超类

DECLARE_WND_SUPERCLASS(NULL, WC_TREEVIEW)   ///< !
WTL : create CtreeViewCtrl On CPaneContainerImpl_第1张图片

/// @file       LsTreeViewCtrl.h

#ifndef __LS_TREEVIEWCTRL_H__
#define __LS_TREEVIEWCTRL_H__

#include "stdafx.h"

typedef CWinTraitsOR<
WS_BORDER
| TVS_HASBUTTONS
| TVS_HASLINES
| TVS_LINESATROOT
| TVS_TRACKSELECT
| TVS_FULLROWSELECT> CTreeCtrlTraits;

class CLsTreeViewCtrl :
    public ATL::CWindowImpl,
    public WTL::CCustomDraw
{
public:
    DECLARE_WND_SUPERCLASS(NULL, WC_TREEVIEW)   ///< !

    CLsTreeViewCtrl();
    ~CLsTreeViewCtrl();

    BEGIN_MSG_MAP(CLsTreeViewCtrl)
    DEFAULT_REFLECTION_HANDLER()
    END_MSG_MAP()
};

#endif  // #ifndef __LS_TREEVIEWCTRL_H__

/// @file       LsTreeViewCtrl.cpp

#include "LsTreeViewCtrl.h"

CLsTreeViewCtrl::CLsTreeViewCtrl()
{

}

CLsTreeViewCtrl::~CLsTreeViewCtrl()
{

}


/// @file       LsPaneContainer.h

#ifndef __LS_PANECONTAINER_H__
#define __LS_PANECONTAINER_H__

#include "atlctrlx.h"

class CLsPaneContainer :
    public WTL::CPaneContainerImpl
{
public:
    DECLARE_WND_CLASS_EX(_T("My_PaneContainer"), 0, -1)

    CLsPaneContainer(void);
    virtual ~CLsPaneContainer(void);

    HWND Create(HWND hWndParent, LPCTSTR lpstrTitle = NULL, DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
        DWORD dwExStyle = 0, UINT nID = 0, LPVOID lpCreateParam = NULL);
};

#endif // #ifndef __LS_PANECONTAINER_H__

/// @file       LsPaneContainer.cpp

#include "stdafx.h"
#include "LsPaneContainer.h"

CLsPaneContainer::CLsPaneContainer(void)
{
}

CLsPaneContainer::~CLsPaneContainer(void)
{
}

HWND CLsPaneContainer::Create(
    HWND hWndParent, 
    LPCTSTR lpstrTitle, 
    DWORD dwStyle,
    DWORD dwExStyle, 
    UINT nID, 
    LPVOID lpCreateParam)
{
    HWND hWnd = NULL;

    hWnd = WTL::CPaneContainerImpl::Create(
        hWndParent, 
        lpstrTitle, 
        dwStyle, 
        dwExStyle, 
        nID, 
        lpCreateParam);

    this->SetPaneContainerExtendedStyle(PANECNT_NOCLOSEBUTTON);

    return hWnd;
}


/// @file       LsPaneContainerPeNodeList.h

#ifndef __LS_PANECONTAINER_PENODELIST_H__
#define __LS_PANECONTAINER_PENODELIST_H__

#include "LsPaneContainer.h"
#include "LsTreeViewCtrl.h"

class CLsPaneContainerPeNodeList :
    public CLsPaneContainer
{
public:
    CLsPaneContainerPeNodeList(void);
    virtual ~CLsPaneContainerPeNodeList(void);

    BEGIN_MSG_MAP(CLsPaneContainerPeNodeList)
    CHAIN_MSG_MAP(CLsPaneContainer)
    REFLECT_NOTIFICATIONS()
    DEFAULT_REFLECTION_HANDLER()
    END_MSG_MAP()

    HWND Create(HWND hWndParent, LPCTSTR lpstrTitle = NULL, DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
                DWORD dwExStyle = 0, UINT nID = 0, LPVOID lpCreateParam = NULL);

private:
    CLsTreeViewCtrl m_CtrlPeTree;
};

#endif // #ifndef __LS_PANECONTAINER_PENODELIST_H__

/// @file       LsPaneContainerPeNodeList.cpp

#include "stdafx.h"
#include "LsPaneContainerPeNodeList.h"

CLsPaneContainerPeNodeList::CLsPaneContainerPeNodeList(void)
{
}

CLsPaneContainerPeNodeList::~CLsPaneContainerPeNodeList(void)
{
}

HWND CLsPaneContainerPeNodeList::Create(
    HWND hWndParent,
    LPCTSTR lpstrTitle,
    DWORD dwStyle,
    DWORD dwExStyle,
    UINT nID,
    LPVOID lpCreateParam)
{
    WCHAR cBuf[MAX_PATH] = {L'\0'};
    HWND    hWnd = NULL;
    HTREEITEM hItem = TVI_ROOT;
    HTREEITEM hCurrent;

    hWnd = CLsPaneContainer::Create(
               hWndParent,
               lpstrTitle,
               dwStyle,
               dwExStyle,
               nID,
               lpCreateParam);

    m_CtrlPeTree.Create(this->m_hWnd, rcDefault);
    this->SetClient(m_CtrlPeTree.m_hWnd);

    // @todo 模拟树节点
    hItem = m_CtrlPeTree.InsertItem(L"root", hItem, TVI_LAST);
    for (int i = 0; i < 100; i++)
    {
        swprintf_s(cBuf, L"%d", i);
        hItem = m_CtrlPeTree.InsertItem(cBuf, hItem, TVI_LAST);
    }

    // @todo 展开整棵树
//     hItem= m_CtrlPeTree.GetFirstVisibleItem();
//     while (hItem != NULL)
//     {
//         m_CtrlPeTree.Expand(hItem,TVE_EXPAND);
//         hItem= m_CtrlPeTree.GetNextItem(hItem, TVGN_NEXTVISIBLE);
//     }

    return hWnd;
}





你可能感兴趣的:(WTL : create CtreeViewCtrl On CPaneContainerImpl)