Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A Tiny Custom List Control

0.00/5 (No votes)
25 Aug 2014 1  
A tiny custom list control

Introduction

Preview:

List control with button and combo box

We can insert a listbox:

List box

We can even insert a dialog:

Dialog

Using the Code

Create Custom List Control

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

The custom list control contains all the CListCtrl's methods.

Its Extended Methods

//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);

The Rectangle Setting Event Callback Function

//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);

Attention

  1. The control that will be inserted into the custom list control must set its parent to the custom list control.
  2. The control with dialog type must be set to child style.

Points of Interest

The way I set the row height is not smart. Can you help me? See CListCtrlCustom::SetRowHeight(...).

Thanks for reading.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here