wtl的CTreeViewCtrl使用

class CDemoView : public CWindowImpl<CDemoView, CTreeViewCtrl>
{
public:
    //DECLARE_WND_CLASS(NULL)
    DECLARE_WND_SUPERCLASS(NULL, CTreeViewCtrl::GetWndClassName())

    BOOL PreTranslateMessage(MSG* pMsg)
    {
        pMsg;
        return FALSE;
    }

    BEGIN_MSG_MAP(CDemoView)
        REFLECTED_NOTIFY_CODE_HANDLER_EX(TVN_ITEMEXPANDING, OnItemExpanding)
        DEFAULT_REFLECTION_HANDLER()
    END_MSG_MAP()

    LRESULT OnItemExpanding(NMHDR* phdr)
    {
        NMTREEVIEW* pnmtv = (NMTREEVIEW*)phdr;

        if (pnmtv->action & TVE_COLLAPSE)
            return TRUE;
        else
            return FALSE;
    }
};

class CMainFrame : 
    public CFrameWindowImpl, 
    public CUpdateUI,
    public CMessageFilter, public CIdleHandler
{
protected:
    CString msg;

public:
    DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)

    CDemoView m_view;
    //...
};
/* 树控制 */

    {
        HTREEITEM hRoot, hItem;
        TCHAR pc_name[64] = { 0 };
        TV_INSERTSTRUCT TCItem;//插入数据项数据结构
        TCItem.hParent = TVI_ROOT;//增加根项
        TCItem.hInsertAfter = TVI_LAST;//在最后项之后
        TCItem.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;//设屏蔽
        TCItem.item.pszText = _T("设备树");
        TCItem.item.lParam = 0;//序号 
        TCItem.item.iImage = 0;//正常图标 
        TCItem.item.iSelectedImage = 1;//选中时图标 
        hItem = m_view.InsertItem(&TCItem);//返回根项句柄 
        m_view.Expand(hItem, TVE_EXPAND);//展开上一级树
        hRoot = hItem;

        MultiByteToWideChar(CP_ACP, 0, troot->Name, strlen(troot->Name) + 1, pc_name,
            sizeof(pc_name) / sizeof(pc_name[0]));
        TCItem.item.pszText = pc_name;
        TCItem.hParent = hItem;
        hItem = m_view.InsertItem(&TCItem);//返回根项句柄 
        m_view.Expand(hRoot, TVE_EXPAND);//展开上一级树
    }

你可能感兴趣的:(wtl,wtl-tree)