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. Drawing without flicker?

Drawing without flicker?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
10 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.
  • A Offline
    A Offline
    Aidman
    wrote on last edited by
    #1

    Hi all, :) Is it possible to draw several shapes directly on a window during a loop without having any flicker? I have tried to use the ValidateRect and InvalidateRect function, but I can’t seem to make them prevent flicker, maybe I am missing something. How do you prevent flicker when drawing directly on a window? :( Aidman » over and out

    J D 2 Replies Last reply
    0
    • A Aidman

      Hi all, :) Is it possible to draw several shapes directly on a window during a loop without having any flicker? I have tried to use the ValidateRect and InvalidateRect function, but I can’t seem to make them prevent flicker, maybe I am missing something. How do you prevent flicker when drawing directly on a window? :( Aidman » over and out

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      Use a memory device context: http://www.codeproject.com/gdi/flickerfree.asp[^] John

      1 Reply Last reply
      0
      • A Aidman

        Hi all, :) Is it possible to draw several shapes directly on a window during a loop without having any flicker? I have tried to use the ValidateRect and InvalidateRect function, but I can’t seem to make them prevent flicker, maybe I am missing something. How do you prevent flicker when drawing directly on a window? :( Aidman » over and out

        D Offline
        D Offline
        Dave Bryant
        wrote on last edited by
        #3

        One way is to use a memory device context (search codeproject for CMemDC), which is essentially a bitmap in memory. Instead of drawing directly to the screen, you draw everything to the memory DC, and then as the last step in the drawing process, you BitBlt the memory DC onto the real DC. This means that if the same part of the DC is drawn multiple times during the drawing process, you won't see any flicker. Dave http://www.cloudsofheaven.org

        A 1 Reply Last reply
        0
        • D Dave Bryant

          One way is to use a memory device context (search codeproject for CMemDC), which is essentially a bitmap in memory. Instead of drawing directly to the screen, you draw everything to the memory DC, and then as the last step in the drawing process, you BitBlt the memory DC onto the real DC. This means that if the same part of the DC is drawn multiple times during the drawing process, you won't see any flicker. Dave http://www.cloudsofheaven.org

          A Offline
          A Offline
          Aidman
          wrote on last edited by
          #4

          hehe... yes I know you can use doublebuffering, but I wanto know if it possible to have a flicker-free graphic without it. Thanks anyway ;) Aidman » over and out

          J 1 Reply Last reply
          0
          • A Aidman

            hehe... yes I know you can use doublebuffering, but I wanto know if it possible to have a flicker-free graphic without it. Thanks anyway ;) Aidman » over and out

            J Offline
            J Offline
            John M Drescher
            wrote on last edited by
            #5

            Quick answer is no. John

            A 1 Reply Last reply
            0
            • J John M Drescher

              Quick answer is no. John

              A Offline
              A Offline
              Aidman
              wrote on last edited by
              #6

              But shouldn't it be possible to use ValidateRect or some other function to prevent an graphic area from updating to the screen? So that you can draw stuff on that area and update it when your done, sort of like when you use BeginPaint and EndPaint? Aidman » over and out

              J R 2 Replies Last reply
              0
              • A Aidman

                But shouldn't it be possible to use ValidateRect or some other function to prevent an graphic area from updating to the screen? So that you can draw stuff on that area and update it when your done, sort of like when you use BeginPaint and EndPaint? Aidman » over and out

                J Offline
                J Offline
                J Dunlap
                wrote on last edited by
                #7

                Not if you're drawing directly to the screen.

                "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                "You must be the change you wish to see in the world." - Mahatma Gandhi

                1 Reply Last reply
                0
                • A Aidman

                  But shouldn't it be possible to use ValidateRect or some other function to prevent an graphic area from updating to the screen? So that you can draw stuff on that area and update it when your done, sort of like when you use BeginPaint and EndPaint? Aidman » over and out

                  R Offline
                  R Offline
                  Ryan Binns
                  wrote on last edited by
                  #8

                  Aidman wrote: But shouldn't it be possible to use ValidateRect or some other function to prevent an graphic area from updating to the screen? Yes, but the part you don't validate will still flicker if you draw over the same part multiple times or if you don't handle WM_ERASEBKGND to prevent the background being erased. It's almost always better to use a memory DC, combined with selective invalidating like you suggested. Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
                  Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

                  J 1 Reply Last reply
                  0
                  • R Ryan Binns

                    Aidman wrote: But shouldn't it be possible to use ValidateRect or some other function to prevent an graphic area from updating to the screen? Yes, but the part you don't validate will still flicker if you draw over the same part multiple times or if you don't handle WM_ERASEBKGND to prevent the background being erased. It's almost always better to use a memory DC, combined with selective invalidating like you suggested. Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
                    Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

                    J Offline
                    J Offline
                    John M Drescher
                    wrote on last edited by
                    #9

                    Ryan Binns wrote: if you don't handle WM_ERASEBKGND to prevent the background being erased. YES! This is very important to avoid filcker even if you use a memory dc. John

                    R 1 Reply Last reply
                    0
                    • J John M Drescher

                      Ryan Binns wrote: if you don't handle WM_ERASEBKGND to prevent the background being erased. YES! This is very important to avoid filcker even if you use a memory dc. John

                      R Offline
                      R Offline
                      Ryan Binns
                      wrote on last edited by
                      #10

                      John M. Drescher wrote: YES! This is very important to avoid filcker even if you use a memory dc. Absolutely! I probably didn't make that clear enough did I :) Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
                      Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

                      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