首页 随笔 乐走天涯 程序资料 评论中心 Tag 论坛 其他资源 搜索 联系我 关于 RSS

A Multi-Level CCheckListbox - 多级列表框


日期: 2000-01-21 14:00 | 联系我 | 关注我: Telegram, Twitter

本程序实现多级列表框(A Multi-Level CCheckListbox).作者 Brett R. Mitchell 的描述:

Recently, I was in the need of a control that allowed the users the ability to check multiple items in a CListbox type of fashion. I would of used the common MFC control CCheckListBox but I needed the items to be presented in a hierarchy and be totally customizable (font, colors, images, etc.) for each individual item. I also thought about using the MFC CTreeCtrl and do my own custom drawing but I really wanted the CListbox look and feel along without the ability to expand and collapse each item. So...here's my solution...

如图所示:

多级列表框 A Multi-Level CCheckListbox

  1. 使用环境: VC++ 6.0
  2. 作者:Brett R. Mitchell
  3. 下载:下载多级列表框(A Multi-Level CCheckListbox), 源代码及演示程序

多级列表框(A Multi-Level CCheckListbox) 示例代码


// Create the Control
LISTITEM* pParentItem = NULL;
m_pCheckList = new CCheckList();
if( !m_pCheckList->Create( CRect(50,50,300,300), this, 10001,
IDB_CHECK, IDB_UNCHECK, IDB_MIDDLECHECK ))
{
 return;
}

// Add some items

// Root Item
pParentItem = m_pCheckListStandard->AddString("Exotics");

// Sub Item
m_ pCheckList ->AddString("Lamborghini", pParentItem );

// Sub Item
m_ pCheckList ->AddString("Corvette", pParentItem );

// Sub Item
m_ pCheckList ->AddString("Vector", pParentItem );

// Sub Item
m_ pCheckList ->AddString("Hummer", pParentItem );

//  Sub-Sub Item
pParentItem = m_ pCheckList ->AddString("Porsche", pParentItem );

//  Sub-Sub Item
m_ pCheckList ->AddString("Boxster", pParentItem );

//  Sub-Sub Item
m_ pCheckList ->AddString("928 S4", pParentItem);

//  Sub-Sub Item
m_ pCheckList ->AddString("959", pParentItem );

// Root Item
m_ pCheckList ->AddString("Luxury");

// Root Item
m_ pCheckList ->AddString("Trucks");

// Root Item
m_ pCheckList ->AddString("Sport Utility Vehicles");

// Root Item
m_ pCheckList ->AddString("Classics");


// Function uses
// Get Total Count
CString csMessage;
csMessage.Format("There are a total of %d items",
 m_pCheckListStandard->GetCount() );

AfxMessageBox(csMessage);

// Get and Set the top index
csMessage.Format("The top index is: %d",
 m_pCheckListStandard->GetTopIndex() );

AfxMessageBox(csMessage);
m_pCheckListStandard->SetTopIndex(6);

// Different ways to get an item
LISTITEM* pItem =
 m_pCheckListStandard->GetItem(
  m_pCheckListStandard->GetTopIndex());

AfxMessageBox(pItem->csText);
pItem = m_pCheckList->GetItem((DWORD)5000);
AfxMessageBox(pItem->csText);

// Get and Set the Item data
DWORD dwID =
 m_pCheckListStandard->GetItemData(
  m_pCheckListStandard->GetTopIndex());

csMessage.Format("The Data for this item is: %ld", dwID );
AfxMessageBox(csMessage);
m_pCheckListStandard->SetItemData(6, 2000);

// Get the text and text length
CString csText;
m_pCheckListStandard->GetText( 6, &csText );
int nTemp = m_pCheckListStandard->GetTextLen( 7 );

// Get and set the current selection
m_pCheckListStandard->SetCurSel(6);
nTemp = m_pCheckListStandard->GetCurSel();

// Get and Set Checks
m_pCheckListStandard->SetCheck(6, CHECKED);
nTemp = m_pCheckListStandard->GetCheck(6);

// Remove one item and all its subitems (if it has them)
m_pCheckListStandard->DeleteString(6);

// Delete eveything
m_pCheckListStandard->ResetContent();


 文章评论

第 1 楼  发表于 2007-05-31 11:55 | fdf 的所有评论
hao dongdong

共有评论 1 条, 显示 1 条。

发表你的评论
如果你想针对此文发表评论, 请填写下列表单:
姓名: * 必填 (Twitter 用户可输入以 @ 开头的用户名, Steemit 用户可输入 @@ 开头的用户名)
E-mail: 可选 (不会被公开。如果我回复了你的评论,你将会收到邮件通知)
反垃圾广告: 为了防止广告机器人自动发贴, 请计算下列表达式的值:
9 x 5 + 5 = * 必填
评论内容:
* 必填
你可以使用下列标签修饰文字:
[b] 文字 [/b]: 加粗文字
[quote] 文字 [/quote]: 引用文字

 
首页 随笔 乐走天涯 猎户星 Google Earth 程序资料 程序生活 评论 Tag 论坛 资源 搜索 联系 关于 隐私声明 版权声明 订阅邮件

程序员小辉 建站于 1997 ◇ 做一名最好的开发者是我不变的理想。
Copyright © XiaoHui.com; 保留所有权利。