Accessing to parent view
-
Hi guys I've got an SDI app and from the view I call a dialog like this. In CMyView.cpp void CMyView::OpenMydialog() { CMyDialog dlg; dlg.SetFather(this); dlg.DoModal(); } and in my dialog I do this In MyDialog.h class CMyView; CMyView *m_pFather; void SetFather(CMyView *p_pFather); and in MyDialog.cpp #include "myappView.h" (but due to this I have to include first myappDoc.h") void CMyDialog::SetFather(CMyView *p_pFather) { m_pFather=p_pFather; } What's the usual (and right) way to acces the parent (View) class without to add all these includes? Now each time I compile , practically all app is compiled again and that's what I want to avoid. Thanks in forwarding Doc
-
Hi guys I've got an SDI app and from the view I call a dialog like this. In CMyView.cpp void CMyView::OpenMydialog() { CMyDialog dlg; dlg.SetFather(this); dlg.DoModal(); } and in my dialog I do this In MyDialog.h class CMyView; CMyView *m_pFather; void SetFather(CMyView *p_pFather); and in MyDialog.cpp #include "myappView.h" (but due to this I have to include first myappDoc.h") void CMyDialog::SetFather(CMyView *p_pFather) { m_pFather=p_pFather; } What's the usual (and right) way to acces the parent (View) class without to add all these includes? Now each time I compile , practically all app is compiled again and that's what I want to avoid. Thanks in forwarding Doc
void CMyView::OpenMydialog() { CMyDialog dlg(this); dlg.DoModal(); } //if you wonna get the parent in your dlg class void CMyDialog::AMethod() { //get the parent CWnd* pWnd = GetParent(); //you can also cast offcourse, but then you^ll need to include the MyView.h in the MyDialog.cpp: CMyView* pMyView = (CMyView*)GetParent(); } Hope this helps you, Greetings, Davy
-
void CMyView::OpenMydialog() { CMyDialog dlg(this); dlg.DoModal(); } //if you wonna get the parent in your dlg class void CMyDialog::AMethod() { //get the parent CWnd* pWnd = GetParent(); //you can also cast offcourse, but then you^ll need to include the MyView.h in the MyDialog.cpp: CMyView* pMyView = (CMyView*)GetParent(); } Hope this helps you, Greetings, Davy
The problem is that if I follow your example I don't have access to the view variables. If I have a member called m_nCalls in my view How do I access to it? If I do CWnd* pWnd = GetParent(); pWnd->m_nCalls I receive compiling a nice error C2039: 'm_nCalls' : is not a member of 'CWnd' :( Doc
-
The problem is that if I follow your example I don't have access to the view variables. If I have a member called m_nCalls in my view How do I access to it? If I do CWnd* pWnd = GetParent(); pWnd->m_nCalls I receive compiling a nice error C2039: 'm_nCalls' : is not a member of 'CWnd' :( Doc
-
Hi guys I've got an SDI app and from the view I call a dialog like this. In CMyView.cpp void CMyView::OpenMydialog() { CMyDialog dlg; dlg.SetFather(this); dlg.DoModal(); } and in my dialog I do this In MyDialog.h class CMyView; CMyView *m_pFather; void SetFather(CMyView *p_pFather); and in MyDialog.cpp #include "myappView.h" (but due to this I have to include first myappDoc.h") void CMyDialog::SetFather(CMyView *p_pFather) { m_pFather=p_pFather; } What's the usual (and right) way to acces the parent (View) class without to add all these includes? Now each time I compile , practically all app is compiled again and that's what I want to avoid. Thanks in forwarding Doc
Another - more "correct" object oriented method - would be to pass the view's pointer to the dialog's constructor (as another poster pointed out). Then when the dialog needs to communicate with the view it would do so via messaging as opposed to directly accessing the view's members, which is an obvious OOP no-no Cheers, Tom Archer - Archer Consulting Group
"Eat your brussel sprouts, Junior. There are starving Chinese children American programmers that would kill for that food!"