WTL : create CtreeViewCtrl On CPaneContainerImpl

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

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

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

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

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

DECLARE_WND_SUPERCLASS(NULL, WC_TREEVIEW)   ///< !

/// @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<CLsTreeViewCtrl, WTL::CTreeViewCtrl, CTreeCtrlTraits>,
    public WTL::CCustomDraw<CLsTreeViewCtrl>
{
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<CLsPaneContainer>
{
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<CLsPaneContainer>::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;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值