-
June 1st, 2002, 01:43 AM
#1
Getting info from a Document in a dialog?
I have a dialog called from my Document, and it needs to access a CMap declared in the document (Doc/View architecture). Any idea how I can do this, since GetParent only works for window types?
Thanks,
DD
-
June 1st, 2002, 05:52 AM
#2
try this:
CYourAppDoc * CYourDialog::GetDocument()
{
POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
CDocTemplate * pSingleDocTemplate = AfxGetApp()->GetNextDocTemplate(pos);
pos = pSingleDocTemplate->GetFirstDocPosition();
return (CYourAppDoc*)pSingleDocTemplate->GetNextDoc(pos);
}
then in some func (in same dialog, of course) call
CYourAppDoc* pDoc = GetDocument();
pDoc->SomeFunc(); // for example....
....don't forget to #include doc header....
stay good
-
June 1st, 2002, 08:50 AM
#3
If the document calls up the dialog (and it should if the dialog is dealing with document data), you can also have a CDocument member of the dialog which the document sets.
CMyDialog dlg;
dlg.m_pDoc = this;
In OnInitDialog()
ASSERT(m_pDoc != NULL);
Steve
-
June 1st, 2002, 08:28 PM
#4
Dear sir,
The following code maybe useful to you:
CView* GetActiveView()
{
CFrameWnd* pFrame = (CFrameWnd*) AfxGetApp()->m_pMainWnd;
ASSERT(pFrame->IsKindOf(RUNTIME_CLASS(CFrameWnd)));
CView *pView = pFrame->GetActiveView();
#if _MFC_VER >= 0x0250
if (pView == NULL)
pView = pFrame->GetActiveFrame()->GetActiveView();
#else
if (pFrame->IsKindOf(RUNTIME_CLASS(CMDIFrameWnd)))
{
CWnd* pWnd = ((CMDIFrameWnd*)pFrame)->MDIGetActive();
if (pWnd)
pFrame = (CFrameWnd*) pWnd;
}
pView = pFrame->GetActiveView();
#endif
return pView;
}
CDocument* GetActiveDocument()
{
CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
if (pFrame->IsKindOf(RUNTIME_CLASS(CMDIFrameWnd)))
{
CMDIChildWnd * pChild =
((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActive();
if ( !pChild )
return NULL;
return pChild->GetActiveDocument();
}
return pFrame->GetActiveDocument();
}
Jack
----------------------------------------------------------
http://www.********.net/ (Xtreme Diagram++ MFC Library with full
source code)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|