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

    Getting a document pointer

    I have a MDI app (Visual C++ 6.0) and I can get the document pointer in
    each of the views. Is there a way for the MainFrame class and/or the
    Application class to get the document pointer as well? I need to store
    some data in the document in either the Frame class or Application class
    that the views will use.



  2. #2
    Join Date
    May 1999
    Location
    Toulouse, France
    Posts
    171

    Re: Getting a document pointer

    To retrieve all the docs from your MainFrame, you may use this, for example:

    CMyApp *myApp =(CMyApp *)AfxGetApp();
    POSITION pos = myApp->m_pDocTemplate->GetFirstDocPosition();
    CMyDoc *pDoc;

    while(pos){
    pDoc = (CMyDoc *)myApp->m_pDocTemplate->GetNextDoc(pos);
    ...
    }

    To get the active one, use CFrameWnd::GetActiveDocument() (see doc for more infos)

    HTH.

    K.

    Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.
    We're talking ****, 'cause life is a 'biz
    You know it is
    Everybody tryin' to get rich
    God ****!
    All I wanna do is live !

    KoRn, Children of the Korn

  3. #3
    Join Date
    Apr 1999
    Posts
    3

    Re: Getting a document pointer

    // I tried this and it seems to work:

    CMDIFrameWnd *pFrame =
    (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;

    // Get the active MDI child window.
    CMDIChildWnd *pChild =
    (CMDIChildWnd *) pFrame->GetActiveFrame();

    // or CMDIChildWnd *pChild = pFrame->MDIGetActive();

    // Get the active view attached to the active MDI child
    // window.
    CMyView *pView = (CMyView *) pChild->GetActiveView();
    CMyDoc* pDoc = pView->GetDocument();
    //
    // you'll need to include: mydoc.h and myview.h in your mainframe header.

    syh


  4. #4
    Join Date
    Apr 1999
    Location
    China
    Posts
    19

    Re: Getting a document pointer

    In MFC, the relation between View and Doc, is control by DocTemplate, if no DocTemplate at APP::InitInstance() , you can not get valide Doc pointer.
    You have to direct use DocTemplate var or Doc var of APP.
    Dong


  5. #5
    Join Date
    Apr 1999
    Posts
    76

    Re: Getting a document pointer

    Thanks to everyone. Program works fine now.


  6. #6
    Join Date
    Jul 1999
    Posts
    30

    Re: Getting a document pointer

    Hi,

    I ran into the same problem with you. You said you have worked it out. Could you kindly send me a sample? Millions of thanks!

    Jason

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