|
Welcome to Ionware Productions website!
|
|
Properties Dialog (ala MFC)
Well, this tutorial is going to be about... You are right, about property dialog! To build it, just follow the steps Author' Web page This is an example screenshot of the program you can make using his code. I only has taken it The basic workings of the Property Dialog are pretty straightforward and easy to understand. You overload To create a dialog we're going to use a a property dialog, simply create a new dialog in Visual Studio' editor and add class CSettingsDlg : public CDialog { DECLARE_DYNAMIC(CSettingsDlg) public: CSettingsDlg(CWnd* pParent = NULL); // standard constructor virtual ~CSettingsDlg(); EPropCtrl m_PropCtrl; IPropertyHost* m_pCurrentHost; void SetPropPointer(IPropertyHost *pHost); // Dialog Data enum { IDD = IDD_SETTINGS }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support virtual BOOL OnInitDialog(); afx_msg void OnSize(UINT nType, int cx, int CY); DECLARE_MESSAGE_MAP() };Well, after you've done it, make sure you have the SetPropPointer function like the one below: void CSettingsDlg::SetPropPointer(IPropertyHost *pHost) { if(pHost !=NULL) { m_pCurrentHost = pHost; m_PropCtrl.SetPropertyHost(pHost); } else { m_pCurrentHost = NULL; m_PropCtrl.SetPropertyChangeListener(NULL); m_PropCtrl.SetPropertyHost(NULL); } } This function will be looking for variable updates and we will call it when the property pointer has been changed. m_PropCtrl.Create(this, IDC_PROP); The best and only way to bind variables inside any class is to derive it from IPropertyHost and implement the following functions: /*! Method details: @param pvProperty - Pointer to the property @param pvNewValue - Pointer to the new value */ virtual bool PropertyChanging(const void* pvProperty , void* pvNewValue); /*! Method details: @param PropList - Const. reference to the property list */ virtual void GetProperties(EPropList& PropList);The first one will be called when a variable has changed it's value inside Property Dialog, and the other one when you need to update or populate that dialog with new values/binds. Let's take a look at the CEntity' class implementation of those functions: bool CEntity::PropertyChanging( const void* pvProperty , void* pvNewValue ) { if(pvProperty == &m_strName) m_strName = *(CString *)pvNewValue; return true; } void CEntity::GetProperties( EPropList& PropList ) { PropList.AddTab("Properties"); PropList.AddPropSeparator(this, "Entity"); PropList.AddPropString(this, "Name", &m_strName, true)->SetComment("Entity' name"); PropList.AddPropInt(this, "ID", &m_uiID, "", false)->SetComment("Auto assigned Unique Identifier"); }As you can see, in PropertyChanging, the first value passed to the function is the pointer to the property that has been changed and the second is the new value for that property. If you want your binded variable to change to the new value, simply return true from the function. If not, return false. Easy! You also can use a more advanced method of checking whether the new value has the value/format you are looking for,and, basing off that, allow or disallow the variable' change. In the second function, GetProperties, you are simply defining the way you are going to allow the user to change the variable. For example, if it is of an integer type, you can present it as textbox. If it's a color (COLORREF) you can present the user with the Color Picker dialog. There are many different controls corresponding to different situations, you take your time and explore some or all of them. The one and only parameter this function provides you with is the list that holds all the controls binded to your values. Adding Properties To add a property, call EPropList' functions such as AddPropInt or AddPropCombo. Some of them may return Postmortem Now what you do is create a dialog just as usual: m_SettingsDlg.Create(IDD_SETTINGS, this); m_SettingsDlg.ShowWindow(SW_SHOW); and call m_SettingsDlg.SetPropPointer with the pointer to the class of the type of IPropertyHost. And that's it. You will Extra Notes To run this tutorial, you need to download and compile PropertyLib software from Beyond Data' website.
|
||||
Ionware Productions © 2003 - 2004. All
rights reserved.
|