I would like to better understand the way to use CDocument class with multi-view application.
The thing I have difficulty to understand is what pointer is retrive by the GetDocument function in the view object. I don't know where I can initialise the data un my CDocument object before creating my view. My Data are not save in a serialize document. The only data I would like to put in the CDocument object are things about a SQL request.
I thing these lines of code associate the dynamic class View and document together.
THE pDocTemplate IS A POINTER TO THE THREE RUNTIME CLASSES
EACH TIME YOU OPEN A FILE THIS POINTER IS USED TO ACCESS THE RUNTIME CLASSES THAT ARE ASSOCIATED WITH THAT FILE
THE BEST PLACE TO STORE DATA IS THE DOCUMENT CLASS BECAUSE WHAT EVER VIEW THAT USES THAT DATA CAN ACCESS THE DATA EASILY BY GetDocument()
We only live once, but we can make many mistakes !
It is approximately what I understand of the CDocument class. But where is the CDocument object.
For example if I have In my CDocument object 2 variables of data.
int Data1;
int Data2;
how can I access the to variables to put data in it to this will be show in my View after. In other way to say, how to acces the pointer retrive by GetDocument?
THE pDocTemplate IS A POINTER TO THE THREE RUNTIME CLASSES
pDocTemplate is a pointer to a document template class that contains member variables set to runtime info when document template object is instantiated. pDocTemplate pointer is added to a template list that is a member of an application class.
Originally Posted by J Stoll
EACH TIME YOU OPEN A FILE THIS POINTER IS USED TO ACCESS THE RUNTIME CLASSES THAT ARE ASSOCIATED WITH THAT FILE
Each time you open a file application retrieves appropriate template pointer and calls template’s member function to create new file or open existing. That function uses stored pointers to runtime info to perform requested operation.
Runtime info pointers are not associated with any file.
If string table contains proper document string and document type is registered with shell, file associated with application can be open using DDE.
Originally Posted by Geof
how can I access the to variables to put data in it to this will be show in my View after.
Question:
Where from (what object) are you trying to initiate document members?
There are only 10 types of people in the world: Those who understand binary and those who do not.
If you're using the Document/View framework as provided by App Wizard, you can call GetDocument() from your view classes to get access to the document.
I will try to use a prctical situation to exaplain what I want to understand.
I have a MDI program with Doc\View support. This programme take data in a SQL database and display it in views. To display information in a view it is necessary to transfert information about the request to the database. ( request string, table name, database name, or other thing for the display ).
Example of view:
User open a dialog box and add information in it for the request to the database. After that the user press a submit button to start de request and display the result in the database.
My problem:
I have informations in the dialog ( request or other things ) I would like to put it in a CDocument object to retrive it after by the view for the display.
MyDoc will be display in MyView and this view is create in MyFrame. In MyView I can call GetDocument to retrive the MyDoc pointer ans access data to display it. It is ok for the display side. But my problem is on the fill side. If I didn't place data in MyDoc when I retrive the pointer it will be retrive a pointer on a object containing no data.
I'm not sure but I have to take data input by the user in the dialog, put it in MyDoc before creating the view. But how to do that ?
I'm not sure but I have to take data input by the user in the dialog, put it in MyDoc before creating the view. But how to do that ?
I hope it will be more clear
That's not typically the way it's done. More typical would be to create the document, frame and view, but just have the view not display anything when there is nothing to display. From a menu, the user could pull up your dialog. Either your document or view could handle the dialog, which would update the document. From that point, call your document's UpdateAllViews() method which would call your view's OnUpdate() method. At that point the view would redraw itself with the appropriate data from the document.
If you really want to get the data before the view, you'd have to call the dialog in the app's OnInitInstance, and override the default framework doc/view creation creating the document seperately and populating it first. Not that hard to to, but not as friendly, particularly if the user may want enter different parameters.
If you really want to get the data before the view, you'd have to call the dialog in the app's OnInitInstance
Why OnInitInstance? What about OnNewDocument virtual override?
Geof :
If you display dialog from OnNewDocument it will appear before main frame window.
You can initialize any member variable you need and after creation of the view OnInitialUpdate will be called allowing view to update own data.
See sample.
There are only 10 types of people in the world: Those who understand binary and those who do not.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.