CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2002
    Posts
    5

    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

  2. #2
    Join Date
    Mar 2001
    Location
    Belgrade, Serbia
    Posts
    629
    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

  3. #3
    Join Date
    Sep 1999
    Location
    Colorado, USA
    Posts
    1,002
    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

  4. #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
  •  





Click Here to Expand Forum to Full Width

Featured