Solved

Accessing Doc data from a dialog...

Posted on 1998-04-21
3
183 Views
Last Modified: 2013-11-20
I need to to display certain data pertaining to my CDocument class in a dialog box(let's say CDlg), and didn't think it was kosher to actually send the pointer to the CDocument object from, say the CView class where I created the CDlg.  To make a long story short, is there a quick way to get a pointer to the current document object in any location?  I know how to do this from the CMainFrame object, but is there some easy was to do it from ANY object?
0
Comment
Question by:salamander
[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
3 Comments
 
LVL 2

Accepted Solution

by:
rayb earned 50 total points
ID: 1301050
Hi Salamander,

Would this work for you?

CDocument *pDoc= AfxGetMainWnd()->GetActiveDocument();


0
 
LVL 2

Expert Comment

by:SamratAshok
ID: 1301051
There is a way to obtain a document pointer from MFC. But if you do not want to
pass pointer because of C++ philosophy, getting pointer from MFC is just a longer
(and painful) way to violate the same rules.

With that in mind, I would either edit the constructors of dialogbox to accomodate just the
specific values or  add a post-construction function to pass data to dialog box.
(you will have to probably call it before showing dialog)

You can access document pointer using App object : DocTemplate List : Document List.

Look for functions like GetNextDocument, GetNextDocTemplate and of course AfxGetApp
in help

Since you have access to App object everywhere. you have access to this everywhere.


0
 

Author Comment

by:salamander
ID: 1301052
Thanks for the help.  I actually need to do this quickly so, forgive me, I am going to fudge a little on my creed of data-hiding and object-oriented political-correctness.  Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 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