Abstract
CListBoxColorPickerST
is a CListBox derived class that shows a colored bar on the left of each item.
This control can be useful in such applications like supervisors of an industrial process where each displayed object
can have a different color based on its current state (Run, stop, failure...); a color legend can be developed
using CListBoxColorPickerST
to visually associate each possible color with a text description.
How to integrate CListBoxColorPickerST in your application
In your project include the following files:
- ListBoxColorPickerST.h
- ListBoxColorPickerST.cpp
With dialog editor create a standard list box called, for example, IDC_LBXCOLORS.
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:
CListBoxColorPickerST m_lbxColors;
Now attach the list box to CListBoxColorPickerST. For dialog-based applications, in your OnInitDialog:
CDialog::OnInitDialog();
m_lbxColors.SubclassDlgItem(IDC_LBXCOLORS, this);
Or in your DoDataExchange:
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LBXCOLORS, m_lbxColors);
Class methods
AddString
Adds a string to the list box.
int AddString(LPCTSTR lpszItem, COLORREF crColor)
InsertString
Inserts a string at a specific location in the list box.
int InsertString(int nIndex, LPCTSTR lpszString, COLORREF crColor)
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, COLORREF crColor)
ResetContent
Clears all the entries from the list box.
void ResetContent()
SetColor
Associates a color with a string at a specific location in the list box.
int SetColor(int nIndex, COLORREF crColor, BOOL bRepaint = TRUE)
GetColor
Returns the color associated with a string at a specific location in the list box.
COLORREF GetColor(int nIndex)
GetSelectedColor
Returns the color associated with the currently selected string in the list box.
COLORREF GetSelectedColor()
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)
SelectColor
Searches for a particular color in the list box. If found the associated
string is then selected. The search ends at the first occurence of the color.
int SelectColor(COLORREF crColor)
GetTextAndColor
Returns a list box item and the associated color.
int GetTextAndColor(int nIndex, LPTSTR lpszBuffer, COLORREF* lpcrColor)
int GetTextAndColor(int nIndex, CString& rString, COLORREF* lpcrColor)
Credits
CListBoxColorPickerST
is based on the control by James R. Twine and Mark Jackson (mark@mjsoft.co.uk).
Disclaimer
THE SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED.
NO REPONSIBILITIES FOR POSSIBLE DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN.
THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.
SoftechSoftware homepage
SoftechSoftware Email