资源简介
自己做的树形控件实现完全树形控件自绘,易懂,易修改。
代码片段和文件信息
// TreeCtrlForTopics.cpp : implementation file
//
#include “stdafx.h“
#include “baseTreeCtrl.h“
//#include “skinscrollwnd.h“
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTreeCtrlForTopics
CbaseTreeCtrl::CbaseTreeCtrl()
{
m_hTreeItemIn = NULL;
m_clrBK = RGB(0x51 0x75 0x94);
m_bEnableControls = TRUE;
m_bEnableSelect = TRUE;
m_bMouseTracking = FALSE;
}
CbaseTreeCtrl::~CbaseTreeCtrl()
{
}
BEGIN_MESSAGE_MAP(CbaseTreeCtrl CTreeCtrl)
//{{AFX_MSG_MAP(CbaseTreeCtrl)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE onmouseleave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT CbaseTreeCtrl::onmouseleave(WPARAM wParamLPARAM lParam)
{
m_bMouseTracking = FALSE;
Invalidate(TRUE);
return TRUE;
}
BOOL CbaseTreeCtrl::SetCheck(HTREEITEM hItem BOOL fCheck)
{
CTreeCtrl::SetCheck(hItem fCheck);
CheckParents(hItem fCheck);
return TRUE;
}
BOOL CbaseTreeCtrl::CheckOneChild(HTREEITEM hItem)
{
HTREEITEM hTreeItem = GetChildItem(hItem);
while(hTreeItem)
{
if(GetCheck(hTreeItem))
{
return TRUE;
}
if(CheckOneChild(hTreeItem))
{
return TRUE;
}
hTreeItem = GetNextItem(hTreeItem TVGN_NEXT);
}
return FALSE;
}
BOOL CbaseTreeCtrl::CheckChildren(HTREEITEM hItem BOOL fCheck)
{
HTREEITEM hTreeItem = GetChildItem(hItem);
while(hTreeItem)
{
CTreeCtrl::SetCheck(hTreeItem fCheck);
CheckChildren(hTreeItem fCheck);
hTreeItem = GetNextItem(hTreeItem TVGN_NEXT);
}
return TRUE;
}
BOOL CbaseTreeCtrl::CheckParents(HTREEITEM hItem BOOL fCheck)
{
HTREEITEM hTreeItemParent = GetNextItem(hItem TVGN_PARENT);
while(hTreeItemParent)
{
BOOL bChecked = fCheck;
if(!bChecked)
{
bChecked = CheckOneChild(hTreeItemParent);
}
SetCheck(hTreeItemParent bChecked);
hTreeItemParent = GetNextItem(hTreeItemParent TVGN_PARENT);
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CTreeCtrlForTopics message handlers
BOOL CbaseTreeCtrl::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
}
void CbaseTreeCtrl::OnLButtonDown(UINT nFlags CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(!m_bEnableControls)
{
SetFocus();
return;
}
HTREEITEM hItemTree = HitTest(point NULL);
if(hItemTree == NULL)
{
return;
}
int nstyle = Getstyle();
if(TVS_CHECKBOXES & nstyle)
{
BOOL bChecked = CTreeCtrl::GetCheck(hItemTree);
CTreeCtrl::OnLButtonDown(nFlags point);
BOOL bCheckedNow = CTreeCtrl::GetCheck(hItemTree);
if(bChecked != bCheckedNow)
{
CheckChildren(hItemTree bCheckedNow);
CheckPar
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11380 2011-06-29 10:59 TreeCtrl\ControlLib\ba
文件 2483 2011-06-29 10:59 TreeCtrl\ControlLib\ba
文件 1561 2011-06-29 10:59 TreeCtrl\ControlLib\ControlLib.cpp
文件 196 2011-06-29 10:59 TreeCtrl\ControlLib\ControlLib.def
文件 4842 2011-06-29 10:59 TreeCtrl\ControlLib\ControlLib.dsp
文件 3089 2011-06-29 10:59 TreeCtrl\ControlLib\ControlLib.rc
文件 2523 2011-06-29 10:59 TreeCtrl\ControlLib\ReadMe.txt
文件 402 2011-06-29 10:59 TreeCtrl\ControlLib\res\ControlLib.rc2
目录 0 2011-06-30 19:33 TreeCtrl\ControlLib\res
文件 382 2011-06-29 10:59 TreeCtrl\ControlLib\Resource.h
文件 17432 2011-06-29 10:59 TreeCtrl\ControlLib\SkinScrollBar.cpp
文件 2152 2011-06-29 10:59 TreeCtrl\ControlLib\SkinScrollBar.h
文件 11178 2011-06-29 10:59 TreeCtrl\ControlLib\skinscrollwnd.cpp
文件 1921 2011-06-29 10:59 TreeCtrl\ControlLib\skinscrollwnd.h
文件 212 2011-06-29 10:59 TreeCtrl\ControlLib\StdAfx.cpp
文件 1462 2011-06-29 10:59 TreeCtrl\ControlLib\StdAfx.h
目录 0 2011-06-30 19:32 TreeCtrl\ControlLib
文件 754 2011-06-23 09:06 TreeCtrl\TestTreeCtrl\ba
文件 1111 2011-06-23 09:06 TreeCtrl\TestTreeCtrl\ba
文件 131142 2011-06-29 10:59 TreeCtrl\TestTreeCtrl\ControlLib.dll
文件 3687 2011-06-20 10:55 TreeCtrl\TestTreeCtrl\ReadMe.txt
文件 1078 2011-06-20 10:55 TreeCtrl\TestTreeCtrl\res\TestTreeCtrl.ico
文件 404 2011-06-20 10:55 TreeCtrl\TestTreeCtrl\res\TestTreeCtrl.rc2
..A.SH. 4608 2011-06-20 14:03 TreeCtrl\TestTreeCtrl\res\Thumbs.db
文件 10038 2011-06-20 13:43 TreeCtrl\TestTreeCtrl\res\tree.bmp
目录 0 2011-06-30 19:32 TreeCtrl\TestTreeCtrl\res
文件 735 2011-06-20 13:43 TreeCtrl\TestTreeCtrl\resource.h
文件 214 2011-06-20 10:55 TreeCtrl\TestTreeCtrl\StdAfx.cpp
文件 1054 2011-06-20 10:55 TreeCtrl\TestTreeCtrl\StdAfx.h
文件 45888 2011-06-20 16:41 TreeCtrl\TestTreeCtrl\TestTreeCtrl.aps
............此处省略17个文件信息
- 上一篇:test30.zip
- 下一篇:方正畅流安装方法详细说明
评论
共有 条评论