Solved

GetDocument() Question

Posted on 2003-11-22
3
759 Views
Last Modified: 2013-11-20
CmfcDoc* CFrontEnd::GetDocument() const
{
//      ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CmfcDoc)));
      return (CmfcDoc*)m_pDocument;
}

CmfcDoc* pDoc=(CmfcDoc*) GetDocument();

I wanna get some data items from CDoument class while not from CView class, how do I achieve this? Thanks
Jack
0
Comment
Question by:luckie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9802384
From any place of CView-derived class you can use GetDocument function to access the document class:

void CFrontEnd::AnyFunction()
{
    GetDocument()->SomeFunction();  // access document functions and members
}
0
 

Author Comment

by:luckie
ID: 9802584
Hi Alex,
Mine is not a CView-derived. Could I do the same with any generic classes?Thanks
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 9803120
From any place if SDI application you can access document class by the following way:

CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CMyView *pView = (CMyView *) pFrame->GetActiveView();
CMyDocument* pDocument = pView->GetDocument();
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question