CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Fill CDocument

  1. #1
    Join Date
    Aug 2001
    Posts
    81

    Fill CDocument

    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.
    Code:
    CMultiDocTemplate* pDocTemplate;
    	pDocTemplate = new CMultiDocTemplate(
    		IDR_MDIWITTYPE,
    		RUNTIME_CLASS(CMDIWithDOCDoc),
    		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    		RUNTIME_CLASS(CMDIWithDOCView));
    	AddDocTemplate(pDocTemplate);
    But after that where is the object to store data?

    Thank you

  2. #2
    Join Date
    Sep 2002
    Location
    land of hurricanes
    Posts
    244

    Re: Fill CDocument

    Code:
    CMultiDocTemplate* pDocTemplate;
    	pDocTemplate = new CMultiDocTemplate(
    		IDR_MDIWITTYPE,
    		RUNTIME_CLASS(CMDIWithDOCDoc),
    		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    		RUNTIME_CLASS(CMDIWithDOCView));
    	AddDocTemplate(pDocTemplate);
    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 !

  3. #3
    Join Date
    Aug 2001
    Posts
    81

    Re: Fill CDocument

    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?

  4. #4
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Fill CDocument

    Quote Originally Posted by J Stoll
    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.

    Quote 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.

    Quote 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.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Fill CDocument

    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.

  6. #6
    Join Date
    Aug 2001
    Posts
    81

    Re: Fill CDocument

    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.

    I have 3 object

    CView MyView
    CMDIChildFrame MyFrame
    CDocument MyDoc.


    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 hope it will be more clear

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Fill CDocument

    Quote Originally Posted by Geof

    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.

  8. #8
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    Re: Fill CDocument

    Maybe you can make your dialog a member of the document class.

    Mitesh.

  9. #9
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Fill CDocument

    Quote Originally Posted by GCDEF
    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.
    Attached Files Attached Files
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  10. #10
    Join Date
    Aug 2001
    Posts
    81

    Re: Fill CDocument

    Thank you for your example. It help me.

  11. #11
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Fill CDocument

    You are welcome.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  12. #12
    Join Date
    Sep 2002
    Location
    land of hurricanes
    Posts
    244

    Re: Fill CDocument

    thank you JohnCz for clarifing the pDocTemplate and runtime classes
    We only live once, but we can make many mistakes !

  13. #13
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Fill CDocument

    You are very welcome.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured