资源简介
源代码,自己继承的CTreeCtrl的自定义树形控件类,添加了很多函数方便使用。

代码片段和文件信息
// MyTreeCtrl.cpp : 实现文件
//
#include “stdafx.h“
#include “MyTreeCtrl.h“
// CMyTreeCtrl
IMPLEMENT_DYNAMIC(CMyTreeCtrl CTreeCtrl)
CMyTreeCtrl::CMyTreeCtrl()
{
}
CMyTreeCtrl::~CMyTreeCtrl()
{
}
BEGIN_MESSAGE_MAP(CMyTreeCtrl CTreeCtrl)
END_MESSAGE_MAP()
// CMyTreeCtrl 消息处理程序
void CMyTreeCtrl::ListInit(DWORD dwNewstyles)//初始化控件
{
DWORD dwstyles = GetWindowLong(this->m_hWnd GWL_style);
dwstyles |= dwNewstyles;
SetWindowLong(this->m_hWnd GWL_style dwstyles);
//m_tree.SetItemHeight(25);
//m_tree.SetTextColor(RGB(00255));
//m_tree.SetBkColor(RGB(255255220));
}
HTREEITEM CMyTreeCtrl::InsertRoot(TV_INSERTSTRUCT &TCItem CString strTemp)//插入根项
{
TCItem.hParent = TVI_ROOT;
TCItem.hInsertAfter = TVI_LAST;
TCItem.item.mask = TVIF_TEXT|TVIF_PARAM;
TCItem.item.pszText = (LPSTR)(LPCSTR)strTemp;
TCItem.item.lParam = 0;
return this->InsertItem(&TCItem);
}
HTREEITEM CMyTreeCtrl::InsertParent(TV_INSERTSTRUCT TCItem HTREEITEM hRoot CString strTemp int i)//插入父项
{
TCItem.hParent = hRoot;
TCItem.item.pszText = (LPSTR)(LPCSTR)strTemp;
TCItem.item.lParam = (i + 1) * 10;
return this->InsertItem(&TCItem);
}
void CMyTreeCtrl::InsertChild(TV_INSERTSTRUCT TCItem HTREEITEM hCur CString strTemp int i int j)//插入子项
{
TCItem.hParent = hCur;
TCItem.item.pszText = (LPSTR)(LPCSTR)strTemp;
TCItem.item.lParam = (i + 1) * 10 + (j + 1);
this->InsertItem(&TCItem);
}
void CMyTreeCtrl::ExpandTree(HTREEITEM hItem)//展开树中的某一项
{
this->Expand(hItemTVE_EXPAND);
HTREEITEM hChild = this->GetChildItem(hItem);
while (hChild)
{
ExpandTree(hChild);
hChild = this->GetNextSiblingItem(hChild);
}
}
void CMyTreeCtrl::ExpandAllTree()//展开该树的所有项
{
HTREEITEM hRoot = this->GetRootItem();
ExpandTree(hRoot);
}
void CMyTreeCtrl::CollapseTree(HTREEITEM hItem)//收起树中的某一项
{
this->Expand(hItemTVE_COLLAPSE);
HTREEITEM hChild = this->GetChildItem(hItem);
while (hChild)
{
CollapseTree(hChild);
hChild = this->GetNextSiblingItem(hChild);
}
}
void CMyTreeCtrl::CollapseAllTree()//收起该树的所有项
{
HTREEITEM hRoot = this->GetRootItem();
CollapseTree(hRoot);
}
void CMyTreeCtrl::CheckSubItems(HTREEITEM hParentBOOL bCheck)
{
TreeView_SetCheckState(this->m_hWndhParentbCheck);
HTREEITEM hItem = TreeView_GetChild(this->m_hWndhParent);
while(hItem)
{
CheckSubItems(hItembCheck);
hItem = TreeView_GetNextSibling(this->m_hWndhItem);
}
}
HTREEITEM CMyTreeCtrl::FindItem(HTREEITEM hItem CString strText)//在某项及其子项中查找内容返回匹配项的HTREEITEM否则返回NULL
{
HTREEITEM hFind;
if(hItem == NULL)
return NULL;
while(hItem != NULL)
{
if(GetItemText(hItem) == strText)
return hItem;
if(ItemHasChildren(hItem))
{
hItem = GetChildItem(hItem);
hFind = FindItem(hItemstrText);
if(hFind)
{
return hFind;
}
else
{
hItem = GetNextSiblingItem(GetParentItem(hItem));
}
}
else
{
hItem = Get
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-02-08 10:19 MyTreeCtrl\
文件 3719 2012-02-08 10:18 MyTreeCtrl\MyTreeCtrl.cpp
文件 871 2012-02-03 16:01 MyTreeCtrl\MyTreeCtrl.h
- 上一篇:arduino控制57步进电机
- 下一篇:聚英调试助手 V1.3.zip
相关资源
- Windows异步套接字网络编程
- VC 获得文件属性 获取文件的创建时
- 基于MVC模式的会员管理系统
- silicon lab公司的收音IC SI47XX全套开发工
- 读者写者问题(读者优先,写者优先
- MFC程序-碰撞的小球
- vc 柱形图 CBarChart
- 用vc 写的导线测量,针对刚学测绘的
- 用VC 编写的仿QQ聊天室程序源代码
- 栅栏填充算法源码(VC)
- 简单的房屋租赁系统
- .net网站服装销售系统(MVC)
-
ob
jectARX给Auto CAD加工具条 - blowfish的vc2008工程.rar
- 画图程序MFC/VC/VC CRectTracker 串行化
- capon波束形成算法-VC实现
- 读取串口数据并画实时曲线的VC 程序
- VC 游戏编程—附源代码
- IpHlpApi.h&IpHlpApi.lib
- vc 6.0开发的流程图编辑器
- VC 天空盒(skyBox)实现(附源代码)
- c MFC 画多边形
- keil vcom windows 7 64bit 驱动
- vc URL编解码类
- vc编写中国象棋详细源码注释并附有视
- VC 围棋源代码
- 用VC 编写的基于SNMP的路由器拓扑程序
- vc利用MFC底层开发的二维GIS管理软件,
- 兰勃托地图投影VC源码
- 清华大学郑莉C 语言程序设计课件
评论
共有 条评论