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. CTreeCtrl with CustomDraw Flickering

CTreeCtrl with CustomDraw Flickering

Scheduled Pinned Locked Moved C / C++ / MFC
c++cssgraphicsdata-structureshelp
10 Posts 4 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.
  • S Offline
    S Offline
    SamwisePl
    wrote on last edited by
    #1

    Hi basically my problem is how to get rid of flickering when i use customdraw. I know about double bufering, bckgnderase and any other solutions, but all of them do not work in my case, because my customdraw is called for each item (when resizing window(mfc behavior)) and for some of them when multiselection happens. CustomDraw is called from OnNotify(need that because i am extending normal tree with columns like in listView - so it look smth like Grid with expandable rows). Cause of all that behavior that i need, got no idea how to apply double buffering into this, cause there's none notification when to bitblt offscreen bitmap into screen. Would appreciate any ideas.

    L V L 3 Replies Last reply
    0
    • S SamwisePl

      Hi basically my problem is how to get rid of flickering when i use customdraw. I know about double bufering, bckgnderase and any other solutions, but all of them do not work in my case, because my customdraw is called for each item (when resizing window(mfc behavior)) and for some of them when multiselection happens. CustomDraw is called from OnNotify(need that because i am extending normal tree with columns like in listView - so it look smth like Grid with expandable rows). Cause of all that behavior that i need, got no idea how to apply double buffering into this, cause there's none notification when to bitblt offscreen bitmap into screen. Would appreciate any ideas.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See WM_SETREDRAW message (Windows)[^].

      S 1 Reply Last reply
      0
      • L Lost User

        See WM_SETREDRAW message (Windows)[^].

        S Offline
        S Offline
        SamwisePl
        wrote on last edited by
        #3

        Richard MacCutchan wrote:

        See WM_SETREDRAW message (Windows)[^].

        Same problem like with bitblt there's no proper place to call that one. MFC calls NM_CUSTOMDRAW for each element. So i've got no control over this "message loop".

        L 1 Reply Last reply
        0
        • S SamwisePl

          Richard MacCutchan wrote:

          See WM_SETREDRAW message (Windows)[^].

          Same problem like with bitblt there's no proper place to call that one. MFC calls NM_CUSTOMDRAW for each element. So i've got no control over this "message loop".

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Take a look at Double-buffered Tree and Listviews[^].

          1 Reply Last reply
          0
          • S SamwisePl

            Hi basically my problem is how to get rid of flickering when i use customdraw. I know about double bufering, bckgnderase and any other solutions, but all of them do not work in my case, because my customdraw is called for each item (when resizing window(mfc behavior)) and for some of them when multiselection happens. CustomDraw is called from OnNotify(need that because i am extending normal tree with columns like in listView - so it look smth like Grid with expandable rows). Cause of all that behavior that i need, got no idea how to apply double buffering into this, cause there's none notification when to bitblt offscreen bitmap into screen. Would appreciate any ideas.

            V Offline
            V Offline
            Victor Nijegorodov
            wrote on last edited by
            #5

            You might want to look at this article: [A custom-drawn TreeList Control](https://www.codeproject.com/Articles/325/A-custom-drawn-TreeList-Control)

            S 1 Reply Last reply
            0
            • S SamwisePl

              Hi basically my problem is how to get rid of flickering when i use customdraw. I know about double bufering, bckgnderase and any other solutions, but all of them do not work in my case, because my customdraw is called for each item (when resizing window(mfc behavior)) and for some of them when multiselection happens. CustomDraw is called from OnNotify(need that because i am extending normal tree with columns like in listView - so it look smth like Grid with expandable rows). Cause of all that behavior that i need, got no idea how to apply double buffering into this, cause there's none notification when to bitblt offscreen bitmap into screen. Would appreciate any ideas.

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              There double buffering technique that is fairly trivial to implement and gives reasonable results for any complex drawing 1.) Your draw routines only draw on a memory context, don't draw to the screen at all in those item draw calls. 2.) You use a standard windows timer which will timeout after a set time and you use that to update the screen. 3.) Anytime you draw to the memory context in step 1 you kill the running any timer and restart it 4.) The timer running out posts off a message and if you use that message to transfer the memory DC to screen, you then dispose of the timer. You should be able to get what happens that each item simply draws itself to the memory DC and will restart the timer. When the last item has been drawn the timer will finally hit it's wait timeout and post off the message which will draw all the items together as one big bitblt draw and no flickering. The requirements 1 memory context (created when window is created), 1 timer which is created and disposed as per above.

              In vino veritas

              S 2 Replies Last reply
              0
              • V Victor Nijegorodov

                You might want to look at this article: [A custom-drawn TreeList Control](https://www.codeproject.com/Articles/325/A-custom-drawn-TreeList-Control)

                S Offline
                S Offline
                SamwisePl
                wrote on last edited by
                #7

                Actually using this one as base. Anyway thx for reply.

                1 Reply Last reply
                0
                • L leon de boer

                  There double buffering technique that is fairly trivial to implement and gives reasonable results for any complex drawing 1.) Your draw routines only draw on a memory context, don't draw to the screen at all in those item draw calls. 2.) You use a standard windows timer which will timeout after a set time and you use that to update the screen. 3.) Anytime you draw to the memory context in step 1 you kill the running any timer and restart it 4.) The timer running out posts off a message and if you use that message to transfer the memory DC to screen, you then dispose of the timer. You should be able to get what happens that each item simply draws itself to the memory DC and will restart the timer. When the last item has been drawn the timer will finally hit it's wait timeout and post off the message which will draw all the items together as one big bitblt draw and no flickering. The requirements 1 memory context (created when window is created), 1 timer which is created and disposed as per above.

                  In vino veritas

                  S Offline
                  S Offline
                  SamwisePl
                  wrote on last edited by
                  #8

                  Very interesting idea, will check it now and tell if it work's for me. Thanks.

                  1 Reply Last reply
                  0
                  • L leon de boer

                    There double buffering technique that is fairly trivial to implement and gives reasonable results for any complex drawing 1.) Your draw routines only draw on a memory context, don't draw to the screen at all in those item draw calls. 2.) You use a standard windows timer which will timeout after a set time and you use that to update the screen. 3.) Anytime you draw to the memory context in step 1 you kill the running any timer and restart it 4.) The timer running out posts off a message and if you use that message to transfer the memory DC to screen, you then dispose of the timer. You should be able to get what happens that each item simply draws itself to the memory DC and will restart the timer. When the last item has been drawn the timer will finally hit it's wait timeout and post off the message which will draw all the items together as one big bitblt draw and no flickering. The requirements 1 memory context (created when window is created), 1 timer which is created and disposed as per above.

                    In vino veritas

                    S Offline
                    S Offline
                    SamwisePl
                    wrote on last edited by
                    #9

                    So i've found answer to my problem. I think that i got best working solution that's : Fast, easy and makes ALL flickering dissapear. So the trick is to set Ctrl's window Exstyle WS_EX_COMPOSITED and the same time handle ON_WM_ERASEBKGND() (just return true or false doesn't metter from what i've observed) and that do the trick.:cool:

                    L 1 Reply Last reply
                    0
                    • S SamwisePl

                      So i've found answer to my problem. I think that i got best working solution that's : Fast, easy and makes ALL flickering dissapear. So the trick is to set Ctrl's window Exstyle WS_EX_COMPOSITED and the same time handle ON_WM_ERASEBKGND() (just return true or false doesn't metter from what i've observed) and that do the trick.:cool:

                      L Offline
                      L Offline
                      leon de boer
                      wrote on last edited by
                      #10

                      You should return true (being a non zero value) otherwise window will remain marked for erasing which somewhere down the track may come back to bite you. Remember the API underworkings aren't fixed you may find an old version of Windows or a new update which decides to use the flag.

                      In vino veritas

                      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