|
-
April 4th, 1999, 08:53 PM
#1
Accessing CDocument-member functions
I´m creating a simple single-document application using the MFC wizard which for demonstration purposes prints various textmessages in the document window. Those can be selected by a few options in the menu-bar. I tried to implement the handler (something like ON_FILE_NEWMSG) for this Menu-option in the main program (in my case, Demo.cpp). However, to access a function (settext(CString)) I defined in the Document class I guess I need to use a pointer to the document to call the function that will change the textmessage ( something like ptrtodoc->settext("Hello world"); ).
The problem about this is that I don´t know how to get this pointer. I know that there is a function called CSingledocTemplate that somehow creates and links the mainframe, the view and the document, but this just returns a Pointer to a SingledocTemplate. Besides, I´m not sure if this pointer is global, so it probably wouldn´t be of any use anyway.
Please help, as this is REALLY beginning to bug me..
-
April 5th, 1999, 07:10 AM
#2
Re: Accessing CDocument-member functions
First -- learn how the doc-view works.
Then, all the displaying functions must be in the view class. All the stuff that has to be displayed must be in the doc class. Each stuff in the doc class must have a pointer to such in the view class so that its data will be accessible for displaying. The pointer should be obtained in the following way:
m_pStuff_in_the_View =
&GetDocument()->m_Stuff_in_the_Doc;
Once you get the pointer to your data, you call your fucntion, which is a member of the View class, and takes a parameter of the needed type:
SetText(m_pStuff_in_the_View);
or just
TextOut(x,y,message);
I write this answer according to my understanding of your problem.
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
|