谁能给个“由treectrl选择项目到Listctrl显示”的例子

sjd163 2003-08-04 12:11:40
sjsjsjd@163.com
...全文
100 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
skybblue 2003-08-05
  • 打赏
  • 举报
回复
已经发过去了!
无敌魔仙 2003-08-04
  • 打赏
  • 举报
回复
up
xiaohedou 2003-08-04
  • 打赏
  • 举报
回复
这里有个处理Tree Control的包装类,你看看:
http://www.codeproject.com/treectrl/rgtree.asp
简单说一下:把这个类包含在你的文件中,建立他的实例,用GetAt( /*[in]*/ POSITION pos)取得数据,后用ListCtrl.AddString()加入。


The control data storage is based on the template CRGTreeT<_ITEMDATA>. It's an object implementing a bi-directional linked list of elements, each containing a member of type ITEMDATA.

template<class _ITEMDATA> class CRGTreeT
{
public:
// Construction / Destruction
CRGTreeT();
~CRGTreeT();

// returns the count of all items
UINT GetItemCount() const;
// returns the count of all child items
UINT GetChildCount( /*[in]*/ POSITION posParent) const;
// returns the root
POSITION GetRootPosition() const;

// returns the parent of an item
POSITION GetParentPosition( /*[in]*/ POSITION pos) const;

// adds an items at the begin of the list
POSITION AddHead( /*[in]*/ const _ITEMDATA *pItemData,
/*[in]*/ POSITION posParent=NULL);
// adds an items at the end of the list
POSITION AddTail( /*[in]*/ const _ITEMDATA *pItemData,
/*[in]*/ POSITION posParent=NULL);

POSITION InsertAfter( /*[in]*/ const _ITEMDATA *pItemData,
POSITION posParent=NULL,
/*[in]*/POSITION posAfter=NULL);
// Remove the item at position pos including all subitems
void RemoveAt( /*[in]*/ POSITION pos);
// Removes all items
void RemoveAll();

// returns the first/last child item of the item at position posParent
POSITION GetChildPosition( /*[in]*/ POSITION posParent,
/*[in]*/ BOOL bFirst=TRUE) const;
// returns the next list element, NULL if none
POSITION GetNextPosition( /*[in]*/ POSITION pos) const;

// returns the previous element, NULL if none
POSITION GetPrevPosition( /*[in]*/ POSITION pos) const

// returning a copy of the ITEMDATA at position pos
void GetAt( /*[in]*/ POSITION pos, /*[out]*/ _ITEMDATA* pItemData) const;
// Returning a pointer to the ITEMDATA at position pos
_ITEMDATA* GetAt( /*[in]*/ POSITION pos);
// replace the ITEMDATA at position pos
void SetAt( /*[in]*/ POSITION pos, /*[in]*/ const _ITEMDATA* pItemData);

// sort childrens of the item at position posParent
BOOL SortChildren( /*[in]*/ POSITION posParent,
/*[in]*/ BOOL bAscending=TRUE);
// search for an item based on the compare function
POSITION Find( /*[in]*/ const _ITEMDATA *pItemData,
/*[in]*/ POSITION posParent);

// setting a callback function for sorting and finding items
CompareFunc SetCompareFunc( /*[in]*/ CompareFunc func);
DeleteFunc SetDeleteFunc( /*[in]*/ DeleteFunc func, LPARAM lParam);

protected:
// remove all childs from an item
void RemoveChilds( POSITION pos);

// quick sort algorithms for sorting up- or downwards
void QSortA( /*[in]*/ CTreeItem **pLow, /*[in]*/ CTreeItem **pHigh);
void QSortD( /*[in]*/ CTreeItem **pLow, /*[in]*/ CTreeItem **pHigh);

private:
CTreeItem m_ItemRoot;
UINT m_nCount;
CompareFunc m_pCompareFunc;
DeleteFunc m_pDeleteFunc;
LPARAM m_lParamDeleteFunc;
};

The messages will be processed in its own window procedure. Some small functions I've implemented directly, the others exists as stand alone functions with the following form

LRESULT On[MessageName]( HWND hwnd, TREE_MAP_STRUCT *ptms,
WPARAM wParam, LPARAM lParam)
There is a data structure holding the characteristics for each tree HWND:

struct TREE_MAP_STRUCT
{
HWND hwnd; // the handle of the control
HWND hWndEdit; // the handle of the controls
// edit window
WNDPROC pOldWndProc; // the old window procedure
int nItemCount; // all items inserted
int nMaxWidth; // max width of the control
int nVScrollPos; // vertical scroll position
int nHScrollPos; // horizontal scroll position
HTREEITEM hItemFirstVisible; // items ...
HTREEITEM hItemSelected;
HTREEITEM hItemEditing;
HTREEITEM hItemClicked;
HIMAGELIST hNormalImageList; // image list
HIMAGELIST hStateImageList;
bool bRedrawFlag; // should the control be redrawed
// on each inserting/erasing
_rgTree rgTree; // the CRGTreeT template
};


16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧