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. OnDraw() troubles....

OnDraw() troubles....

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
5 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.
  • B Offline
    B Offline
    bitpusher
    wrote on last edited by
    #1

    Hello, My app draws its own array of lines with a CButton array inside the OnDraw() method. However, when resizing the window, the lines look good, except that the background of the previous CButton window positions is white (erased). Upon overloading the OnEraseBackground() method in the CButton class, I see that it’s called AFTER the lines are drawn in OnDraw(). How do I get the background erase method to execute before the lines are drawn? Or, how do I get the CButtons to be updated COMPLETELY before the lines are drawn (the code draws the lines after calling the CButton.MoveWindow() methods ). thanks, JennyP

    J B 2 Replies Last reply
    0
    • B bitpusher

      Hello, My app draws its own array of lines with a CButton array inside the OnDraw() method. However, when resizing the window, the lines look good, except that the background of the previous CButton window positions is white (erased). Upon overloading the OnEraseBackground() method in the CButton class, I see that it’s called AFTER the lines are drawn in OnDraw(). How do I get the background erase method to execute before the lines are drawn? Or, how do I get the CButtons to be updated COMPLETELY before the lines are drawn (the code draws the lines after calling the CButton.MoveWindow() methods ). thanks, JennyP

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

      Very Strange, the OnEraseBkgnd should always be called before OnDraw. Anyway, one possible solution would be to call ExcludeClipRect or ExcludeUpdateRgn in the OnDraw function so that any future drawing will not draw over what has already drawn. Note: The above may lead to unusual drawing, if OnDraw is realy called before OnEraseBkgnd. What I recommend is to see if you can reproduce the problem in a simple test program (the smaller the better). This will allow one of us to see how OnEraseBkgnd is being called first (or you to see how that is happening). I have found that if you override the OnEraseBkgnd to return TRUE and override the OnDraw function, so that it calls ExcludeClipRect or ExcludeUpdateRgn to validate anything you have drawn, is a great way to elimenate any flicker. If you find a solution please post it (or write and article [prefered]). If what you describe is actualy happening, I feel for you. It's one of those things that makes us want to pound are head against the wall (very depressing). Good Luck, and keep progamming! INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

      B 1 Reply Last reply
      0
      • B bitpusher

        Hello, My app draws its own array of lines with a CButton array inside the OnDraw() method. However, when resizing the window, the lines look good, except that the background of the previous CButton window positions is white (erased). Upon overloading the OnEraseBackground() method in the CButton class, I see that it’s called AFTER the lines are drawn in OnDraw(). How do I get the background erase method to execute before the lines are drawn? Or, how do I get the CButtons to be updated COMPLETELY before the lines are drawn (the code draws the lines after calling the CButton.MoveWindow() methods ). thanks, JennyP

        B Offline
        B Offline
        bobi_zcl
        wrote on last edited by
        #3

        what's mean "with a CButton array",which class does th OnDraw() method belong to? your friend:bobi

        B 1 Reply Last reply
        0
        • B bobi_zcl

          what's mean "with a CButton array",which class does th OnDraw() method belong to? your friend:bobi

          B Offline
          B Offline
          bitpusher
          wrote on last edited by
          #4

          Thanks for the reply. The View class contains an array of CButtons that it creates upon init-dialog. Then, in the View’s OnDraw() method, these buttons are repositioned (MoveWindow()) based on the user’s resizing the overall view. After calling MoveWindow(), I draw a bunch of lines (dc->LineTo()). When the app is running and the user resizes the view, the lines all have blank squares imprinted over them where the CButton(s) used to be (i.e., before they were moved with MoveWindow()). When I insert debug TRACE()s, I see that the CButton’s OnEraseBackground method is temporally executed AFTER the View’s OnDraw() is completed. I suspect that the MoveWindow() simply puts a message in the queue for the CButtons to erase themselves. However, I want this operation to complete immediately before the lines are drawn. Any suggestions? Thanks! JennyP

          1 Reply Last reply
          0
          • J John R Shaw

            Very Strange, the OnEraseBkgnd should always be called before OnDraw. Anyway, one possible solution would be to call ExcludeClipRect or ExcludeUpdateRgn in the OnDraw function so that any future drawing will not draw over what has already drawn. Note: The above may lead to unusual drawing, if OnDraw is realy called before OnEraseBkgnd. What I recommend is to see if you can reproduce the problem in a simple test program (the smaller the better). This will allow one of us to see how OnEraseBkgnd is being called first (or you to see how that is happening). I have found that if you override the OnEraseBkgnd to return TRUE and override the OnDraw function, so that it calls ExcludeClipRect or ExcludeUpdateRgn to validate anything you have drawn, is a great way to elimenate any flicker. If you find a solution please post it (or write and article [prefered]). If what you describe is actualy happening, I feel for you. It's one of those things that makes us want to pound are head against the wall (very depressing). Good Luck, and keep progamming! INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen

            B Offline
            B Offline
            bitpusher
            wrote on last edited by
            #5

            Thanks for the reply! View class contains an array of CButtons, so the CButton’s Erase is being called after the View’s OnDraw() method which moves the CButtons (MoveWindow()). Please see my other reply to this thread for a more complete description (I don’t want to double-post). Thanks! JennyP

            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