65.9K
CodeProject 正在变化。 阅读更多。
Home

一个微型的自定义列表控件

starIconstarIconstarIconstarIconstarIcon

5.00/5 (7投票s)

2014年8月26日

CPOL
viewsIcon

107769

downloadIcon

661

一个微型的自定义列表控件

下载演示

下载 CustomListCtrl.rar

引言

预览

List control with button and combo box

我们可以插入一个listbox

List box

我们甚至可以插入一个对话框

Dialog

Using the Code

创建自定义列表控件

m_pListCtrl = new CListCtrlCustom();
m_pListCtrl->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, rcListCtrl, this, IDC_STATIC_RECT+1);

该自定义列表控件包含所有 CListCtrl 的方法。

它的扩展方法

//Get extended control
// If the grid has no control, return NULL
CWnd *GetCtrl(int nRow, int nCol);

//Get text normal
// If the grid has no control, return CListCtrl::GetItemText.Or return CWnd::GetWindowText
CString GetText(int nRow, int nCol);

//Add any control to the grid

BOOL SetItemEx(int nItem, int nSubItem, CWnd *pExCtrl);

//Set the row height

BOOL SetRowHeight(int nHeight);

//Register the rectangle setting event

void RegOnSettingRect(LPFUNC_RESIZE_CTRL pfnResizeExCtrl);

矩形设置事件回调函数

//Definition
//return TRUE, that means control rectangle has been set. 
//Return FALSE, the control will be fill to the grid.
typedef BOOL (CALLBACK *LPFUNC_SETTING_RECT)
	(CListCtrlCustom *pListCtrl, CWnd *pCtrl, CRect &rectGrid);

注意

  1. 要插入到自定义列表控件中的控件必须将其父窗口设置为自定义列表控件。
  2. 要插入的对话框必须设置为子窗口样式。

关注点

我设置行高的方式不是最好的。你能帮我改进它吗?请参阅 CListCtrlCustom::SetRowHeight(...)

感谢阅读。

历史

  • 2015/4/20 - 修复了一些错误并制作了一个特殊的控件示例
© . All rights reserved.