介绍 本文展示了一个具有图标和文本的所有者绘制列表框的实现。 在编程之前,你可以使用资源编辑器来创建一个必须设置属性的列表框模板。如果想要在列表框中显示(该图标仅支持32x32维大小的图像),请将您喜爱的图标导入到项目中,然后添加ListBoxCH.h和ListBoxCH。cpp,两个文件到您的项目,并添加以下行顶部,您想使用CListBoxCH:Hide 复制Code
#include "ListBoxCH.h"
然后添加以下语句来实现所有者绘制列表框:复制Code
// attach dialog template to the CWnd object
m_ListBox.SubclassDlgItem(IDC_ICON_LIST,this);
// add item
m_ListBox.AddItem("MFC",AfxGetApp()->LoadIcon(IDR_MAINFRAME));
初始所有者绘制列表框:隐藏复制Code
m_ListBox.SetCurSel(0); // set default selected index.
CListBoxCH有一些操作。成员函数可以设置或更改所有者绘制列表框表面:隐藏复制Code
class CListBoxCH: public CListBox
{
...
// Operations
public:
// set active selected color
void SetSelColor(COLORREF clr);
// set inactive background (unselected) color
void SetBgColor(COLORREF clr);
// change or set current select index
void SetCurSel(int curSel);
// set text color
void SetTextColor(COLORREF clr);
// display separator edge ?
void EnableEdge(BOOL bEnable);
// get current selected index
int GetCurSel();
...
}
结论 这个所有者绘制列表框非常简单。您可以将代码添加到该类中,也可以将其他消息处理程序添加到该类中。 编程的快乐! 本文转载于:http://www.diyabc.com/frontweb/news243.html