Re: document class
Here`s my document class implementation so far with the CProperty
class.
class CProperty
{
public:
CProperty();
~CProperty();
void SetValue(const CString & name, int value)
{
CString svalue;
svalue.Format(_T("%d"), value);
SetValue(name, svalue);
}
virtual CString GetValue(const CString & name);
virtual void SetValue(const CString & name, const CString & value);
};
class CMIAppDoc : public CDocument
{
protected:
CMIAppDoc();
DECLARE_DYNCREATE(CMIAppDoc)
public:
virtual BOOL OnNewDocument();
CProperty *GetProp() {return &XmlFile;};
void Init(CWnd *wnd);
protected:
CXmlFile XmlFile;
DECLARE_MESSAGE_MAP()
};
The document class has the only member of the xml file class (CXmlFile
XmlFile). In the OnNewDocument I will load the xml file. I also set
the CProperty variable pointer in the CDisplay class, so that the
CDisplay class has access to the xml file class if a query will
arrive.
BOOL CMIAppDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
//load xml file
//XmlFile.LoadUserXml(_T("userdata.xml"));
XmlFile.LoadUserXml(_T("userdata.xml"));
//global display class varialbe g_DispInfo -> set CProperty varialbe
in CDisplay class
g_DispInfo.Init(XmlFile);
//test: get value from the xml file
CString value = g_DispInfo.GetValue(_T("display:brightness"));
return TRUE;
}
In the view, there`s one button installed (so far), and if the user
clicks on this button the following method will be called to open the
CDisplaydialog from the document class.
void CMIAppView::OnBnClickedMenuDisplay()
{
GetDocument()->Init(this);
}
Before starting the dialog, I will transmit the xmlfile class pointer
from the document class (CXmlFile XmlFile).
void CMIAppDoc::Init(CWnd *wnd)
{
CDmxDialog dlg(wnd);
dlg.Init(XmlFile);
dlg.DoModal();
}
And that`s my dialog class:
class CDmxDialog :
public CDialog
{
public:
CDmxDialog(CWnd* pParent = NULL);
~CDmxDialog(void);
virtual BOOL PreTranslateMessage(MSG* pMsg);
enum { IDD = IDD_DLG_DMX };
virtual void DoDataExchange(CDataExchange* pDX);
void Init(CProperty& propdlg);
protected:
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
CProperty *propdlg;
};
void CDmxDialog::Init(CProperty& prop)
{
propdlg = ∝
}
With the CProperty pointer I have the possiblilty to call the xml file
class to get a name/value pair.
BOOL CDmxDialog::OnInitDialog()
{
CDialog::OnInitDialog();
//get value from the xml file class
CString value = propdlg->GetValue(_T("display::brightness"));
return TRUE;
}
I`m not sure if it is the way you would suggest... and I didn`t
install the std::map so far, because I do not know which would be the
best way to do that (see one of my earlier posts from today).
best regards
Hans