Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Document/View question

Document/View question

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiontutoriallearning
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 7 Offline
    7 Offline
    7stud
    wrote on last edited by
    #1

    Hi, I'm just starting Visual C++, and in my book--Ivor Horton's Beginning Visual C++ 6--there is an initial section talking about how "data" is stored in a document, and the view displays all or part of the data in a document. Then it goes into how to draw in a window with functions like LineTo() and Arc(), but what confuses me is those functions are in the OnDraw() function in the view class. The first line of the OnDraw() function is this: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); which seems to make sense--my thought was we would be using pDoc to store the data in the document object and then display it with the view object, but the next lines are: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); pDC->MoveTo(50,50); pDC->LineTo(50,200); } And, when I compile that, it draws a line in the application window. Well, as you can see pDoc was never used to access the document object, and yet the view class displayed data in the application window--I thought the view displays all or part of the data in a document. It seems to me the document got left out of the equation. What's the explanation for that?

    C R J B 4 Replies Last reply
    0
    • 7 7stud

      Hi, I'm just starting Visual C++, and in my book--Ivor Horton's Beginning Visual C++ 6--there is an initial section talking about how "data" is stored in a document, and the view displays all or part of the data in a document. Then it goes into how to draw in a window with functions like LineTo() and Arc(), but what confuses me is those functions are in the OnDraw() function in the view class. The first line of the OnDraw() function is this: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); which seems to make sense--my thought was we would be using pDoc to store the data in the document object and then display it with the view object, but the next lines are: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); pDC->MoveTo(50,50); pDC->LineTo(50,200); } And, when I compile that, it draws a line in the application window. Well, as you can see pDoc was never used to access the document object, and yet the view class displayed data in the application window--I thought the view displays all or part of the data in a document. It seems to me the document got left out of the equation. What's the explanation for that?

      C Offline
      C Offline
      ColinDavies
      wrote on last edited by
      #2

      7stud wrote: CSketcher* pDoc = GetDocument(); I think that should be CSketcherDoc* pDoc = GetDocument(); Unless you have gone to the trouble of renaming the class. Check you have a CSketcherDoc class Yes Doc/View is confusing. 1. Remember you never see the document with it but a view of it inside a frame. 2. You can change the View of the data but the data does not actually change. Regardz Colin J Davies

      *** WARNING *
      This could be addictive
      **The minion's version of "Catch :bob: "

      It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox

      1 Reply Last reply
      0
      • 7 7stud

        Hi, I'm just starting Visual C++, and in my book--Ivor Horton's Beginning Visual C++ 6--there is an initial section talking about how "data" is stored in a document, and the view displays all or part of the data in a document. Then it goes into how to draw in a window with functions like LineTo() and Arc(), but what confuses me is those functions are in the OnDraw() function in the view class. The first line of the OnDraw() function is this: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); which seems to make sense--my thought was we would be using pDoc to store the data in the document object and then display it with the view object, but the next lines are: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); pDC->MoveTo(50,50); pDC->LineTo(50,200); } And, when I compile that, it draws a line in the application window. Well, as you can see pDoc was never used to access the document object, and yet the view class displayed data in the application window--I thought the view displays all or part of the data in a document. It seems to me the document got left out of the equation. What's the explanation for that?

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        7stud wrote: It seems to me the document got left out of the equation. You're right - that's a terrible example and speaks volumes about the author and his/her editing crew. Also, as Colin pointed out, it should be CSketcherDoc* pDoc = GetDocument();, not CSketcher* .... A better example would have obtained the coordinates used in the MoveTo() and LineTo() calls from the document. This would reinforce the notion that the document stores the data which is simply rendered by the view. A different view class might simply list the coordinates in a tabular form (perhaps in CListCtrl) instead of drawing within the view. Hope this helps. /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

        7 1 Reply Last reply
        0
        • R Ravi Bhavnani

          7stud wrote: It seems to me the document got left out of the equation. You're right - that's a terrible example and speaks volumes about the author and his/her editing crew. Also, as Colin pointed out, it should be CSketcherDoc* pDoc = GetDocument();, not CSketcher* .... A better example would have obtained the coordinates used in the MoveTo() and LineTo() calls from the document. This would reinforce the notion that the document stores the data which is simply rendered by the view. A different view class might simply list the coordinates in a tabular form (perhaps in CListCtrl) instead of drawing within the view. Hope this helps. /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

          7 Offline
          7 Offline
          7stud
          wrote on last edited by
          #4

          Also, as Colin pointed out, it should be CSketcherDoc* pDoc = GetDocument();, not CSketcher* That was a result of my typo. Thanks for the reply.

          1 Reply Last reply
          0
          • 7 7stud

            Hi, I'm just starting Visual C++, and in my book--Ivor Horton's Beginning Visual C++ 6--there is an initial section talking about how "data" is stored in a document, and the view displays all or part of the data in a document. Then it goes into how to draw in a window with functions like LineTo() and Arc(), but what confuses me is those functions are in the OnDraw() function in the view class. The first line of the OnDraw() function is this: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); which seems to make sense--my thought was we would be using pDoc to store the data in the document object and then display it with the view object, but the next lines are: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); pDC->MoveTo(50,50); pDC->LineTo(50,200); } And, when I compile that, it draws a line in the application window. Well, as you can see pDoc was never used to access the document object, and yet the view class displayed data in the application window--I thought the view displays all or part of the data in a document. It seems to me the document got left out of the equation. What's the explanation for that?

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            Simple, it is just a bad example. What I mean by that is it is incomplete. Your conclusions of how it works is correct. The information/data is stored in the document and is displayed in the view. What information and how it is displayed is up to the veiw that is displaying it. One example would be a program that displays numaric data in various forms in different views (using the same data): a spread sheet showing the actual numeric data, a view showing a bar chart or some other type of chart of the same data. When the data is changed in the spread sheet the document is updated with the new data and a message is sent informing all views that the document has changed (been modified) and they need to update their views to reflect the change. There are some interesting examples in the MSDN Library, if you can find them. INTP

            7 1 Reply Last reply
            0
            • J John R Shaw

              Simple, it is just a bad example. What I mean by that is it is incomplete. Your conclusions of how it works is correct. The information/data is stored in the document and is displayed in the view. What information and how it is displayed is up to the veiw that is displaying it. One example would be a program that displays numaric data in various forms in different views (using the same data): a spread sheet showing the actual numeric data, a view showing a bar chart or some other type of chart of the same data. When the data is changed in the spread sheet the document is updated with the new data and a message is sent informing all views that the document has changed (been modified) and they need to update their views to reflect the change. There are some interesting examples in the MSDN Library, if you can find them. INTP

              7 Offline
              7 Offline
              7stud
              wrote on last edited by
              #6

              Thanks for the reply.

              1 Reply Last reply
              0
              • 7 7stud

                Hi, I'm just starting Visual C++, and in my book--Ivor Horton's Beginning Visual C++ 6--there is an initial section talking about how "data" is stored in a document, and the view displays all or part of the data in a document. Then it goes into how to draw in a window with functions like LineTo() and Arc(), but what confuses me is those functions are in the OnDraw() function in the view class. The first line of the OnDraw() function is this: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); which seems to make sense--my thought was we would be using pDoc to store the data in the document object and then display it with the view object, but the next lines are: void CSketcherView::OnDraw(CDC* pDC) { CSketcher* pDoc = GetDocument(); pDC->MoveTo(50,50); pDC->LineTo(50,200); } And, when I compile that, it draws a line in the application window. Well, as you can see pDoc was never used to access the document object, and yet the view class displayed data in the application window--I thought the view displays all or part of the data in a document. It seems to me the document got left out of the equation. What's the explanation for that?

                B Offline
                B Offline
                Bob Stanneveld
                wrote on last edited by
                #7

                Hello, Since you're a beginner whos learing, not everything gets pointed out in detail! I'm almost sure that when you read and learn more that the document will be used inside the OnDraw() and other functions! (I'm missing 1 line in the code! the 2nd line should be:

                ASSERT_VALID(pDoc);

                ) Good luck...

                A student knows little about a lot. A professor knows a lot about little. I know everything about nothing.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups