Abstract
CListBoxST
is a CListBox
derived class that tries to reproduce the look and feel of the same control
that appears under Windows XP when a CD without autorun.inf is inserted into the CD-Rom drive.
Each list box item can be enabled or disabled, can have a icon on the left and its text can be multi-line.
Even if almost the same visual effects can be obtained using a standard CListCtrl
control, there are
some differences that make CListBoxST
better:
- Easy to use
- Standard CListBox methods
- Disabled items
- Multi-line text
- Methods to move items up, down, at top, at bottom
- Different hilight styles
How to integrate CListBoxST in your application
In your project include the following files:
- ListBoxST.h
- ListBoxST.cpp
With the dialog editor create a standard list box called, for example, IDC_LBXITEMS
.
You need to set the following properties:
The Notify
property is not mandatory but it will be required to catch messages from the list box, like for example, the Double-click
event.
Then create a member variable for this list box:
CListBoxST m_lbxItems;
CImageList m_ImageList;
Now attach the list box to CListBoxST
. For dialog-based applications, in your OnInitDialog
:
CDialog::OnInitDialog();
m_lbxItems.SubclassDlgItem(IDC_LBXITEMS, this);
Or in your
DoDataExchange
:
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LBXITEMS, m_lbxItems);
To support icons, a image list must be associated to the control:
BOOL bRetValue = FALSE;
HICON hIcon = NULL;
bRetValue = m_ImageList.Create(32, 32, ILC_COLOR32 | ILC_MASK, 5, 1);
ASSERT(bRetValue == TRUE);
hIcon = AfxGetApp()->LoadIcon(IDI_SHELL32_203);
m_ImageList.Add(hIcon);
hIcon = AfxGetApp()->LoadIcon(IDI_SHELL32_141);
m_ImageList.Add(hIcon);
m_lbxItems.SetImageList(&m_ImageList);
m_lbxItems.AddString(_T("First item"), 0);
m_lbxItems.AddString(_T("Second item\nThis is multi-line"), 1);
Class methods
AddString
Adds a string to the list box.
int AddString(LPCTSTR lpszItem, int nImage = -1L)
InsertString
Inserts a string at a specific location in the list box.
int InsertString(int nIndex, LPCTSTR lpszString, int nImage = -1L)
DeleteString
Deletes a string from the list box.
int DeleteString(int nIndex)
ReplaceString
Replaces a string at a specific location in the list box.
int ReplaceString(int nIndex, LPCTSTR lpszString, int nImage = -1L)
ResetContent
Clears all the entries from the list box.
void ResetContent()
SetImageList
Sets the image list to use in the list box.
void SetImageList(CImageList* pImageList)
SetImage
Sets the image to use in a list box item.
void SetImage(int nIndex, int nImage, BOOL bRepaint = TRUE)
GetImage
Returns the image index associated to a list box item.
void GetImage(int nIndex, LPINT lpnImage)
SetItemData
Sets the 32-bit value associated with the list box item.
int SetItemData(int nIndex, DWORD dwItemData)
GetItemData
Returns the 32-bit value associated with the list box item.
DWORD GetItemData(int nIndex)
SetItemDataPtr
Sets a pointer to a list box item.
int SetItemDataPtr(int nIndex, void* pData)
GetItemDataPtr
Returns a pointer of a list box item.
void* GetItemDataPtr(int nIndex)
MoveUp
Moves a list box item up by one position.
int MoveUp(int nIndex, BOOL bSetCurSel = TRUE)
MoveDown
Moves a list box item down by one position.
int MoveDown(int nIndex, BOOL bSetCurSel = TRUE)
MoveTop
Moves a list box item to the top most position.
int MoveTop(int nIndex, BOOL bSetCurSel = TRUE)
MoveBottom
Moves a list box item to the bottom most position.
int MoveBottom(int nIndex, BOOL bSetCurSel = TRUE)
EnableItem
Enables or disables a list box item.
void EnableItem(int nIndex, BOOL bEnable = TRUE, BOOL bRepaint = TRUE)
IsItemEnabled
Specifies whether a list box item is enabled.
BOOL IsItemEnabled(int nIndex)
SetRowSelect
Sets how a selected list box item will be highlighted.
void SetRowSelect(BYTE byRowSelect = ST_FULLROWSELECT, BOOL bRepaint = TRUE)
GetVersionI
Returns the class version as a short value.
static short GetVersionI()
GetVersionC
Returns the class version as a string value.
static LPCTSTR GetVersionC()
History
- v1.0 (13/March/2002) First release
Disclaimer
The software and the accompanying files are distributed
"as is" and without any warranties whether expressed or implied. No responsibilities
for possible damages or even functionality can be taken. The user must assume
the entire risk of using this software.