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...

如图所示:

  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 条。

当前页面是本站的 Google AMP 版本。
欲查看完整版本和发表评论请点击:完整版 »

 

程序员小辉 建站于 1997
Copyright © XiaoHui.com; 保留所有权利。