Completely Customizable Properties Window


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

A recently needed a properties window that was completely customizable. It also had to support editable combo boxes and send back messages when a property had been altered. I did find a couple other property windows available, but they didn't provide the customization that I needed. Instead of hacking up someone else's code to add my features, I decided to write another one with the functionality I wanted. So here it is...

The control is based off of CListBox, therefore all CListbox functions are available. The following functions are also available to change the way the properties window looks:

void	SetFont(CFont* pFont);
void	SetBkColor(COLORREF crColor);
void	SetPropertyBkColor(COLORREF crColor);
void	SetHighlightColor(COLORREF crColor);
void	SetLineStyle(COLORREF crColor, int nStyle = PS_SOLID);
void	SetBoldSelection(BOOL bBoldSelection);
void	SetTextColor(COLORREF crColor);
void	SetTextHighlightColor(COLORREF crColor);
void	SetPropertyTextColor(COLORREF crColor);

The next group of functions provide the ability to add the different properties to the control. It currently supports Combo Boxes, text fields, toggle fields, font selection fields, color selection fields and Static fields.
BOOL	AddString(CString csText);

BOOL	AddString(CString csText, int nType, 
                CString csData, int nPropertySelected = 0, 
                int nAlignment = DT_LEFT, 
                BOOL bComboEditable = FALSE, 
                BOOL bComboSorted = FALSE);

BOOL	AddString(CString csText, COLORREF crColor, 
                int nAlignment = DT_LEFT);

BOOL	AddString(CString csText, CFont* pFont, 
                int nAlignment = DT_LEFT);

The only one that probably needs explanation is the second 'AddString' function. The 'nType' parameter can be either ID_PROPERTY_TEXT or ID_PROPERTY_STATIC or ID_PROPERTY_BOOL or ID_PROPERTY_PATH or ID_PROPERTY_COMBO_LIST. Font and Color should use the other two 'AddString' functions. The 'csData' parameter needs to be formatted delimited by the '!' character. (see example below). The other parameter that needs explanation is 'nPropertySelected'. This is used to set the selected item in a combobox or set the bool value to true or false. (one again, see example below)

In order to get the data back out of the properties, use the following functions.

bool	GetProperty(int nItem, CString* pText);	
bool	GetProperty(int nItem, bool* bValue);	
bool	GetProperty(int nItem, COLORREF* crColor);	   
bool	GetProperty(int nItem, LOGFONT*	LogFont);
bool	GetProperty(int nItem, CStringArray* pArray, 
                  int* SelectedItem = NULL);
bool	GetProperty(int nItem, int* SelectedItem, 
                  CString* csText = NULL);

One final feature is a message it sends back to the parent window when a property has been changed. The ID for the message is ID_PROPERTY_CHANGED. Just trap this message in the parent with the standard ON_MESSAGE MACRO. The first parameter will be the item that changed. The second parameter will be this items type. (COMBO, TEXT, Etc. ) Here's an example.

Declaration of the Message to trap in the BEGIN_MESSAGE_MAP:


Declaration of the function:

LONG CParentClass::OnPropertyChanged(UINT wItemChanged, 
                                     LONG lPropertyType)

Declaration of the function in the .h parent class file:

afx_msg LONG OnPropertyChanged(UINT wItemChanged, LONG lPropertyType);

Here's an example of how to create, set GUI contraints, add properties, and get values from the control.

// Create the list box font
m_pListBoxFont = new CFont();
m_pListBoxFont->CreateFont(14, 0, 0, 0, FW_NORMAL, 0, 0, 0,
                           ANSI_CHARSET, OUT_TT_PRECIS,
                           CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 
                           VARIABLE_PITCH | FF_SWISS,
// Create a Property Font
m_pPropertyFont = new CFont();
m_pPropertyFont->CreateFont(16, 0, 0, 0, FW_NORMAL, 0, 0, 0, 
                            ANSI_CHARSET, OUT_TT_PRECIS, 
                            CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 
                            VARIABLE_PITCH | FF_SWISS, "system");	
// Create the Control
m_pPropertyListCtrl = new CPropertyListCtrl();
                            CRect(200,100,550,300), this, 
// Set some attributes (Completly Optional)
m_pPropertyListCtrl->SetLineStyle(RGB(74,109,132), PS_SOLID);

// Add the Properties
m_pPropertyListCtrl->AddString("Static Text",
                               "C:\\Windows", 0, DT_RIGHT);

m_pPropertyListCtrl->AddString("Text Property",
                               "This is some text", 0, DT_RIGHT);

m_pPropertyListCtrl->AddString("Toggle Property",
                               "True!False", 0, DT_RIGHT);

m_pPropertyListCtrl->AddString("Color Property",
                               09,165), DT_RIGHT);

m_pPropertyListCtrl->AddString("Font Property",

m_pPropertyListCtrl->AddString("File Property",
                               "\\Dealer.bmp!Bitmap Files "
                               "(*.BMP)|*.bmp|All Files (*.*)"
                               "|*.*|", 0, DT_RIGHT);

m_pPropertyListCtrl->AddString("Combobox Property",
                               2, DT_RIGHT, TRUE, TRUE);

// Get the Properties
// Text and Path
CString csText;
m_pPropertyListCtrl->GetProperty(0, &csText);	

// Toggle
bool bValue;
m_pPropertyListCtrl->GetProperty(1, &bValue);
// Color
m_pPropertyListCtrl->GetProperty(2, &crColor);

// Font
m_pPropertyListCtrl->GetProperty(3, &lf);

// Combo Box
CStringArray Items;
m_pPropertyListCtrl->GetProperty(5, &Items);

// Combo Box (get selected item index and text)
int nSelectedItem;
m_pPropertyListCtrl->GetProperty(5, &nSelectedItem, &csText);


Download source - 9 Kb
Download demo project - 26 Kb


  • some thing wrong with visual style

    Posted by c_m_ on 08/23/2010 02:15pm

    I find the visual style will change the behave of the listbox,with the visual style the OnSelchange and OnDblclk function will be trigered when m_pCurItem==0 and this will crash the program ,without the visual style this will never happen.

  • Exactly what I needed!

    Posted by Legacy on 02/04/2004 08:00am

    Originally posted by: Mouse

    thank you very much for sharing this wonderful code!

  • thanks

    Posted by Legacy on 08/17/2003 07:00am

    Originally posted by: Dr. Evil

    fantastic control,
    great work. thanks heaps.
    pity the comments are populated
    by idiots trying to promote stuff to
    buy though. advertise somewhere else

  • Here's another excellent properties control, one of the best !!!

    Posted by Legacy on 07/29/2003 07:00am

    Originally posted by: Scott Evans

    I just ran across this control the other day, very nice!

  • Multi-line text?

    Posted by Legacy on 03/16/2003 08:00am

    Originally posted by: Greg Ennis

    How can I do a multi-line text property?

  • How do you change an existing properties value?

    Posted by Legacy on 10/10/2002 07:00am

    Originally posted by: MarkgM

    Using CPropertyListCtrl, is there a way to programmatically change the text
    in a text property after that property has been created?
    // Create the property
    m_FieldList->AddString("First Text Property",
    "theValue", 0, DT_RIGHT);
    And later:
    // Set the edit control's value
    ??? how to get to it?

  • AGreat control... but there is a problem with the ComboBox.

    Posted by Legacy on 07/31/2002 07:00am

    Originally posted by: Gazza

    Great control... but there is a problem with the ComboBox.
    When a combo-item is clicked on, the pull-down list only appears within the constraints of the main list-control window, and does not overlay outside it.

  • Another great properties control

    Posted by Legacy on 01/12/2002 08:00am

    Originally posted by: Noemie Bigard

    Found this fresh one at http://www.aircom.org

  • Bug when reset() is called

    Posted by Legacy on 10/24/2001 07:00am

    Originally posted by: Hans van Amstel

    When a reset is called on the CPropertyListCtrl it results in a crash in the DrawItem method.

    This can be fixed by adding a call to ResetContent() at the end of the Reset() method.

    void CPropertyListCtrl::Reset()

    // Clear the List
    POSITION Pos = m_Items.GetHeadPosition();
    m_pCurItem = (PROPERTYITEM*)m_Items.GetNext(Pos);
    delete m_pCurItem->pBrush;
    delete m_pCurItem;

    // Reset the listbox content


  • ExPropertiesList

    Posted by Legacy on 09/29/2001 07:00am

    Originally posted by: Mike Philis

    Do you need a powerfull PropertiesList? Check this out:


  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date