Completely Customizable Properties Window
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:
ON_MESSAGE(ID_PROPERTY_CHANGED, OnPropertyChanged)
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, "arial"); // 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(); m_pPropertyListCtrl->Create(WS_CHILD|WS_BORDER|WS_VISIBLE |LBS_NOTIFY|WS_VSCROLL|WS_HSCROLL |LBS_HASSTRINGS|LBS_OWNERDRAWFIXED, CRect(200,100,550,300), this, ID_PROPERTYLIST); // Set some attributes (Completly Optional) m_pPropertyListCtrl->SetFont(m_pListBoxFont); m_pPropertyListCtrl->SetBkColor(RGB(214,227,239)); m_pPropertyListCtrl->SetTextColor(RGB(74,109,132)); m_pPropertyListCtrl->SetTextHighlightColor(RGB(80,80,80)); m_pPropertyListCtrl->SetHighlightColor(RGB(246,246,220)); m_pPropertyListCtrl->SetPropertyBkColor(RGB(255,255,255)); m_pPropertyListCtrl->SetPropertyTextColor(RGB(0,0,192)); m_pPropertyListCtrl->SetBoldSelection(TRUE); m_pPropertyListCtrl->SetLineStyle(RGB(74,109,132), PS_SOLID); // Add the Properties m_pPropertyListCtrl->AddString("Static Text", ID_PROPERTY_STATIC, "C:\\Windows", 0, DT_RIGHT); m_pPropertyListCtrl->AddString("Text Property", ID_PROPERTY_TEXT, "This is some text", 0, DT_RIGHT); m_pPropertyListCtrl->AddString("Toggle Property", ID_PROPERTY_BOOL, "True!False", 0, DT_RIGHT); m_pPropertyListCtrl->AddString("Color Property", RGB(57, 09,165), DT_RIGHT); m_pPropertyListCtrl->AddString("Font Property", m_pPropertyFont, DT_RIGHT); m_pPropertyListCtrl->AddString("File Property", ID_PROPERTY_PATH, "D:\\Code\\C++\\32bit\\" "Programs\\Blackjack\\Images" "\\Dealer.bmp!Bitmap Files " "(*.BMP)|*.bmp|All Files (*.*)" "|*.*|", 0, DT_RIGHT); m_pPropertyListCtrl->AddString("Combobox Property", ID_PROPERTY_COMBO_LIST, "Porsche!BMW!Mercedes!Lotus!Ford!" "Chevy!Kia!Dodge!Nissan!Toyota", 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 COLORREF crColor; m_pPropertyListCtrl->GetProperty(2, &crColor); // Font LOGFONT lf; 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);
Downloads
Download source - 9 KbDownload demo project - 26 Kb

Comments
some thing wrong with visual style
Posted by c_m_ on 08/23/2010 07:15amI 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.
ReplyExactly what I needed!
Posted by Legacy on 02/04/2004 12:00amOriginally posted by: Mouse
thank you very much for sharing this wonderful code!
Reply-andy
thanks
Posted by Legacy on 08/17/2003 12:00amOriginally 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
****heads.
Reply
Here's another excellent properties control, one of the best !!!
Posted by Legacy on 07/29/2003 12:00amOriginally posted by: Scott Evans
I just ran across this control the other day, very nice!
Replyhttp://www.codejock.com/products/propertygrid/
Multi-line text?
Posted by Legacy on 03/16/2003 12:00amOriginally posted by: Greg Ennis
How can I do a multi-line text property?
ReplyHow do you change an existing properties value?
Posted by Legacy on 10/10/2002 12:00amOriginally posted by: MarkgM
ReplyAGreat control... but there is a problem with the ComboBox.
Posted by Legacy on 07/31/2002 12:00amOriginally 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.
Reply
Another great properties control
Posted by Legacy on 01/12/2002 12:00amOriginally posted by: Noemie Bigard
Found this fresh one at http://www.aircom.org
ReplyNoemie
Bug when reset() is called
Posted by Legacy on 10/24/2001 12:00amOriginally posted by: Hans van Amstel
ReplyExPropertiesList
Posted by Legacy on 09/29/2001 12:00amOriginally posted by: Mike Philis
ReplyLoading, Please Wait ...