自定义控件Windows 2008 R2Windows 2008Win8Windows VistaWindows 7Windows 2003VC++Visual Studio 2010Windows XPMFC初学者开发Visual StudioWindowsC++
一个微型的自定义列表控件





5.00/5 (7投票s)
一个微型的自定义列表控件
引言
预览
我们可以插入一个listbox
我们甚至可以插入一个对话框
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);
注意
- 要插入到自定义列表控件中的控件必须将其父窗口设置为自定义列表控件。
- 要插入的对话框必须设置为子窗口样式。
关注点
我设置行高的方式不是最好的。你能帮我改进它吗?请参阅 CListCtrlCustom::SetRowHeight(...)
。
感谢阅读。
历史
- 2015/4/20 - 修复了一些错误并制作了一个特殊的控件示例