|
-
April 7th, 1999, 06:41 PM
#1
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.
-
April 8th, 1999, 04:05 AM
#2
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
-
April 8th, 1999, 06:54 PM
#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
-
April 8th, 1999, 07:16 PM
#4
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
-
April 8th, 1999, 08:21 PM
#5
Re: Getting a document pointer
Thanks to everyone. Program works fine now.
-
July 18th, 1999, 02:29 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|