Click here to Skip to main content
Click here to Skip to main content

Delphi/VB/VS.NET-style ObjectInspector Control

By , 4 Aug 2001
 

Sample Image #1 Sample Image #2

Introduction

This control is an implementation of a Delphi/VB/VS.NET - Style Object-Inspector. I use this control in many of my applications' property pages to let the user quickly change application settings. I've tried to keep things as simple as possible, although usage of this control may look a bit strange at first sight - the interfaces of the control doesn't resemble the interfaces of other MFC controls, since it's intended to be special purpose control for changing properties only.

The documentation is sparse, because I do not have much time to write documentation. However, the included demo is hopefully a help in understanding how to use the features of the control.

Features

The control supports many build-in property types (although adding your own propery-types should be no problem) :

  • bool
  • short
  • int
  • float
  • double
  • CString
  • CStringList
  • COLORREF
  • COleDateTime

Usage

To use this control in your own application, add CObjectInspector.cpp, CColorButton.cpp and CColourPopup.cpp to your project file. Open the resource editor and place a custom control on your dialog. In the control's properties enter "ObjectInspectorCtrl" as window-classname. Add a CObjectInspector variable to your dialog class :

CObjectInspector m_OI;

Add a DDX_Control handler to your DoDataExchange function :

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Control(pDX, IDC_OI, m_OI);
	//}}AFX_DATA_MAP
}

Override OnInitDialog to customize the Object-Inspector and to add groups and properties :

BOOL CMyDialog::OnInitDialog()
{
	CDialog::OnInitDialog();

	CObjectInspector::CProperty *pGroup;
	
	// Create new property group
	m_OI.AddProperty (pProp = new CObjectInspector::CProperty("Group"));

	// Add properties to the group
	pProp->AddProperty (new CObjectInspector::CProperty("Integer-Value", &m_nIntValue));
	pProp->AddProperty (new CObjectInspector::CProperty("Bool Value", &m_bBoolVal));
}

Override OnNotify to receive notification messages from the control :

BOOL CMyDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
{
    if (wParam == IDC_OI)
    {

       CObjectInspector::NM_OIVIEW *nmHdr = (CObjectInspector::NM_OIVIEW*) lParam;

       // OIVN_ITEMCHANGED is sent after the user has changed a property
       if (nmHdr->hdr.code == OIVN_ITEMCHANGED)
       {
           // Do some stuff (use nmHdr->pProperty to access the altered property)
       }

       // OIVN_ITEMCHANGING is sent when the user is currently editing a property
       if (nmHdr->hdr.code == OIVN_ITEMCHANGING)
       {
           // Do some stuff (use nmHdr->pProperty to access the currently edited property)
       }
    }
	
    return CDialog::OnNotify(wParam, lParam, pResult);
}

Known issues

Navigation with the cursor keys is quite unsatisfactorily.

Acknowledgments

  • Chris Maunder for his color picker
  • Keith Rule for his Memory DC class

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

About the Author

Gunnar Bolle
Web Developer
Germany Germany
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRemaining Errors that Need to be Fixed....memberchris17529 Apr '06 - 6:09 
1. Open a list with lots of items. Make sure there is enough to have a scroll bar. Now close all the items to make the scroll bar disappear. When the scroll bar disappears there is a white line remaining from the boarder of the scroll bar through all the controls.
2. Make two drop down sections and put some items in each drop down. Select the first control in the first dropdown. (make sure the control is in edit mode under the value column) Then close the first drop down section. For some reason the value column cell next to the second drop down doesn't have the right color.
3. Create a color control and below that another color control. Now change the first color control with to a different color. When the color control closes the 2nd color control disappears until the user clicks somewhere?
 
Chris
GeneralFix: Entering in negative values for Shorts and Integersmemberchris17521 Apr '06 - 6:24 
Find the CreateControlFromType and replace the beginning of the function with the following..
CWnd *CObjectInspector::CProperty::CreateControlFromType()
{
	CWnd *pWndCtrl = NULL;
 
	switch (m_ptType)
	{
	case ptFloat :
	case ptDouble :
	case ptShort :
	case ptInteger : 

GeneralFix: Entering in negative values for Floats and Doublesmemberchris17521 Apr '06 - 6:07 
In the ObjectInspector.h file find the constructors for the float and double values. Change the "Min" to be fMin = ((-1 *FLT_MAX)+1) and dblMin = ((-1 *DBL_MAX)+1). Note there are 2 contructors for floats and 2 constructors for doubles.
 
I am not sure if theses are the greatest negative values but they work.
 
Chris
 
-- modified at 12:07 Friday 21st April, 2006
QuestionHow to change the Scroll Amountmemberchris17521 Apr '06 - 6:02 
In the ObjectInspector.cpp under the function OnVScroll find the two if statements below and mess with their values....
if (nSBCode == SB_LINEDOWN && m_nScrollPos < m_nScrollRange) 
	m_nScrollPos += 14;
 
if (nSBCode == SB_LINEUP && m_nScrollPos > 0) 
	m_nScrollPos -= 14;

 
Chris
GeneralColor Popup Flaw...memberchris17521 Apr '06 - 5:59 
The problem is that any control directly below the color popup control sometimes doesn't get painted when the color popup is closed.
Chris
 
-- modified at 12:21 Friday 21st April, 2006
GeneralChange This to Fix Check Buttonmemberchris17519 Apr '06 - 3:39 
Go to line 1279 in the ObjectInspector.cpp and change the following...
if (pProperty->m_ptType == ptBool && !pProperty->m_bRadio)
to the following...
if (pProperty->m_ptType == ptBool && !pProperty->m_bRadio && pProperty->GetValueRect().PtInRect(point))

 
Chris
GeneralUse this to update data after closing controlmemberchris17519 Apr '06 - 1:51 
Isn't it so annoying when you are using this control and you have to click away for this stupid thing to update. In my situation I have this as a properties dialog box and I will have the user modify the properties and then close the dialog. The control would never gets the last changed control so I added this function to the ObjectInspector class inside a public section and I call it just before the dialog box is closed.
 
void CObjectInspector::UpdateEditingProperty()
{
	if (m_pEditingProperty != NULL)
		m_pEditingProperty->EndEdit();
}

 
Chris
 
-- modified at 9:28 Wednesday 19th April, 2006
GeneralBug in CalculateScrollRangememberEinstand15 Aug '05 - 23:13 
in ObjectInspector.cpp
inside the function "CObjectInspector::CalculateScrollRange"
The calaulate of the scroll range is wrong.
It should be
 
m_nScrollRange = nItemsVisible * m_nCellHeight - (m_rtClientRect.Height()-m_nHeaderHeight);
 
instead of
 
m_nScrollRange = nItemsVisible * m_nCellHeight - m_rtClientRect.Height();

GeneralBug reports part 2. - The FixesmemberYogurt11 Aug '03 - 3:37 
In the OnMouseMove event one should check whether the splitter is moved at all, before invalidating:
 
     if (m_bSplitterMoving && point.x < m_rtClientRect.right && point.x > 0 && point.x > m_nMinPropertyColWidth && (m_rtClientRect.Width() - point.x) > m_nMinValueColWidth )
     {
          if (m_nXSplitterPos != point.x) {   // <- ***INSERT***
               m_nXSplitterPos = point.x;
               InvalidateRect(m_rtClientRect,FALSE);
          }                                                   // <- ***INSERT***
     }
 

About boolean items moving to the left:
One should call SetRectangles with the same aligned rectangle as for the DrawFrameControl calls. Now it works fine.
 

In DrawItems, one should reset the scroll position when removing the scroll bar:
     if (m_nOverallItemHeight < (m_rtClientRect.Height() - m_nHeaderHeight ) && m_bScrollbarVisible)
     {
          m_nScrollPos = 0;                           // <- ***INSERT***
          m_bScrollbarVisible = false;
          Invalidate(TRUE);
          return;
     }
 

 
Is there any way to update the downloadables according to my fixes?
GeneralBug reports (even if the author doesn't update this article...)memberYogurt11 Aug '03 - 2:24 
1. Radio buttons are basically ill.
a.) It might be my mistake but I haven't found any way to tell which control belongs to which value of the attached variable.
b.) Select "Normal" style in the demo project. Now the appearance switches to the "W2K" style, though the radio buttons still indicate the "Normal" style. If you select another row, the look reverts to the correct style.
 
2. The selected boolean control moves 2 pixels to the left, making it looking unaligned. I found the place where 2 is added though I don't understand why the selected line is drawn incorrectly.
 
3. When a new boolean line is selected, its state is changed. In my taste it should happen only if the user clicks in the value column.
 
4. In the beginning of the InitInstance function, the whole Enable3dControls stuff must be enclosed as
#if _MFC_VER < 0x0700
...
#endif
because they are obsolete in MFC 7.0.
 
5. If the control is set to smaller width than that of the first column, a horizontal scroll bar should have been displayed.
 
6. Mouse wheel should scroll the list one row at a time instead of one pixel.
 
7. There is some 1-or-2-pixel size miscalculation: the top of the first row below the header is overdrawn with gray.
 
I'll try to fix the above problems.
Generalsmall bugsussDaniel Harth6 Jun '03 - 2:38 
ObjectInspector.cpp, line 1007 should say
if (pProperty->m_Childs.size() != 0)
instead of
if (pProperty->m_Childs.size != 0)
 
Otherwise on VC++.NET it won't compile with an obscure error message
QuestionUpdate?memberhero3blade26 May '03 - 16:31 
Good article! But it seems that the author never comes here and updates his article according to our bug reports.
GeneralDelete Property - DynamicsussAnonymous2 Aug '02 - 23:50 
Hello,
 
good control. I plan to use the control in dynamic enviroment. You can select objects and you get a property list. How can i remove propterty or how can i reset the objectinspector without close the dialog ??
 
many Thanks
 
ThomasSmile | :)
GeneralSomething wrong with the link.memberAnonymous25 Sep '01 - 23:24 
..
GeneralWin95 problemsmemberAnonymous6 Aug '01 - 9:41 
If you scroll up or down, the font is changing and the pictures of radio and checkbutton are changing to an unidentifical char.Confused | :confused:
QuestionBroken link??memberAnonymous6 Aug '01 - 9:15 

The link:
http://www.codeproject.com/miscctrl/ObjectInspector/ObjectInspector_src.zip
 
doesn't go anywhere....Eek! | :eek:

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 5 Aug 2001
Article Copyright 2001 by Gunnar Bolle
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid