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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC drawing confusion

MFC drawing confusion

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsc++game-devquestionannouncement
3 Posts 3 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.
  • M Offline
    M Offline
    Madhur Baheti
    wrote on last edited by
    #1

    Can someone please clear my confusion about the major function calls related to WM_PAINT and the sequence in which they are called. I want to know when these functions: OnUpdate OnInitialUpdate UpdateAllViews OnDraw InvalidateRect are called - whether before or after WM_PAINT, and in what sequence. I've read that InvalidatRect just adds the rectangle to the update region, but it seems to me that a call to it also causes the window to be repainted immediately, or in ther words, a WM_PAINT is passed. Is that true? It would be great if someone can explain me the MFC drawing sequence and procedure in detail. U see, i have just begun with VC and my project is entirely graphics based (OpenGL). So its imperative that i get a good grasp on the drawing mechanism. Despo for your replys. Thanks.

    C M 2 Replies Last reply
    0
    • M Madhur Baheti

      Can someone please clear my confusion about the major function calls related to WM_PAINT and the sequence in which they are called. I want to know when these functions: OnUpdate OnInitialUpdate UpdateAllViews OnDraw InvalidateRect are called - whether before or after WM_PAINT, and in what sequence. I've read that InvalidatRect just adds the rectangle to the update region, but it seems to me that a call to it also causes the window to be repainted immediately, or in ther words, a WM_PAINT is passed. Is that true? It would be great if someone can explain me the MFC drawing sequence and procedure in detail. U see, i have just begun with VC and my project is entirely graphics based (OpenGL). So its imperative that i get a good grasp on the drawing mechanism. Despo for your replys. Thanks.

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

      The only virtual methods which are called by the MFC framework are those with OnXXX. OnInitialUpdate is called after the view is attached to a document but before the view is initially displayed. OnUpdate is called if you change the document data and call UpdateAllViews. So OnUpdate is called by UpdateAllViews. The default implemenation is also called by OnInitialUpdate and it invalidates the entire client area and so it will be repainted if the next WM_PAINT messages is received. UpdateAllViews should be called if you changed the documents data and so the view of the document must be marked invalid so that it is repainted in the next WM_PAINT message! So it forces the views of the document to display the changed data. As I said above UpdateAllViews calls OnUpdate of all views which are attached to this document (except the sender view). Note: you can prevent that OnUpdate invalidates the whole client area, if you overwrite UpdateAllViews/OnUpdate and pass a hint object with the information which part of the view must be updated in order to refelect the document changes! InvalidateRect adds the given rectangle to the windows update region. The update region will be repainted if the next WM_PAINT message is received. It is used by OnUpdate to invalidate the given region of the view. OnDraw will be called by the MFC framework in order to display the document. So OnDraw is called if a WM_PAINT message has been received.

      1 Reply Last reply
      0
      • M Madhur Baheti

        Can someone please clear my confusion about the major function calls related to WM_PAINT and the sequence in which they are called. I want to know when these functions: OnUpdate OnInitialUpdate UpdateAllViews OnDraw InvalidateRect are called - whether before or after WM_PAINT, and in what sequence. I've read that InvalidatRect just adds the rectangle to the update region, but it seems to me that a call to it also causes the window to be repainted immediately, or in ther words, a WM_PAINT is passed. Is that true? It would be great if someone can explain me the MFC drawing sequence and procedure in detail. U see, i have just begun with VC and my project is entirely graphics based (OpenGL). So its imperative that i get a good grasp on the drawing mechanism. Despo for your replys. Thanks.

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        OnUpdate and OnInitialUpdate are called by the framework. OnInitialUpdate is called when the view is first created, and can be used to perform some initial setup before it then calls OnUpdate. OnUpdate is called by the framework in response to a call to CDocument::UpdateAllViews. You normally call UpdateAllViews if you've modified something in the document. This allows multiple views of the same document to be updated (maybe you have a CAD drawing, with different view windows showing different viewpoints of the design). UpdateAllViews calls OnUpdate for all views attached to the document, apart from the one passed in the pSender parameter. CWnd::InvalidateRect is a simple Windows wrapper function (wrapping ::InvalidateRect) which tells Windows that a certain area of the window needs to be redrawn. When your thread's message queue is empty (apart from timer messages, which are the lowest priority), Windows posts a WM_PAINT message for each window that has an invalid region. MFC handles this in CView::OnPaint by retrieving the window's DC, calling OnPrepareDC to allow it to be set up correctly, then calling OnDraw(). OnPrepareDC doesn't do anything in CView's implementation; CScrollView overrides it to set up the scroll extents correctly. This allows you to use a single co-ordinate system whatever the current position of the scroll bars. OnDraw() is also called when you use MFC's built-in printing support. This enables you to support both drawing to the screen and to a printer using the same code. Most of the functions you're discussing are implemented in VIEWCORE.CPP. If you haven't installed the MFC source code, you may find it helpful to do so. The book MFC Internals by George Shepherd and Scot Wingo is still a good reference, despite being 8 years old; the core of MFC has barely changed since version 4.0.

        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