Stop child window from flickering when resizing a MFC dialog

Terkunci Stop child window from flickering when resizing a MFC dialog

  • 30 Juli 2012 22:19
     
     

    I have search high and low for a solution to my problem. I know what the cause is, but I can't seem to make it go away. Let me explain....

    I have an application that reads an XML file and displays the various sections of XML data in a Tab Control. There are 7 different tabs. All of them flicker, but only in the Tab Control window. The area outside of the Tab Control which has some buttons, does not flicker.

    I have reduced my code down to just one tab, so I can solve it for one tab and then just scale up. I can provide any or all of my reduced code, if you need it.

    So, we all know what is causing the problem. The window of the Tab Control is being redrawn in quick succession every time I make the window bigger or smaller. I need to have all the stuff that I have in the Tab Control only redraw once after the window has re-sized. Since I use a List Control, I also re-size it's columns. I also move the buttons and other controls I have on the Tab Control as I am re-sizing.

    I am a newbie to MFC, but not C++. I have tried, with no success, these 2 very good methods, using the bitblt method and deferwindowpos. I fear that I was just not doing something in the incorrect order, but I don't know. I understand the concepts behind both methods as I have read a lot about them. In short, using the bitblt method is double buffering. Create the window in memory until it is done, then show it. Repeat for the next change. The deferwindowpos method is a just wait until I am done changing things, then I will tell you when to show the window with all the changes.

    So, now you know what I am trying to accomplish, and what I have tried. Which one is the best way to solve this problem. And show or teach me how to do it so I can make it work and hopefully learn something. A step-by-step example would be nice. Please don't direct me to another page. I think I have looked at just about all of them. Most of them seem to be incomplete or not quite useful to my particular problem. Thanks in advance.

Semua Balasan

  • 31 Juli 2012 9:29
     
     Saran Jawaban
    See WM_CLIPCHILDREN. This excludes unwanted painting of child controls. Also try returning OnEraseBknd() TRUE.

    Thanks, Renjith V R


  • 31 Juli 2012 14:06
     
     

    I have clip children and clip siblings both set to true in the main dialog's properties and I have tried OnEraseBknd() TRUE and FALSE. I still have a lot of flicker.

    I want to point out that the flicker is most notable on the list control, which is in a tab control, and its tab(s) also flicker. This is a clue.

    Thanks.

  • 31 Juli 2012 17:48
     
     

    Are you using MFC controls or custom controls?

    Are you doing any extra painting for Listbox and Dialog?


    Thanks, Renjith V R

  • 31 Juli 2012 18:35
     
     Jawab

    The problem is solved, but it turns out that the solution was neither of the ones I have been trying.

    All I had to do was to add SWP_NOREDRAW as a flag to the SetWindowPos() for the Tab Control's OnSize() function where I handle its resizing. (only that one)  I then invalidated the rectangles that needed to be redrawn. They were just a couple of long slender ones on the far right and bottom of my dialog window.

    Now the window has very little flicker, which I can live with.

  • 01 Agustus 2012 5:09
     
     
    Is this issue occurred in CListBox. I.e not subclassed?

    Thanks, Renjith V R

  • 03 Agustus 2012 8:49
    Moderator
     
     

    Hi,

    Welcome here. 
    Thanks for your post and sharing answer here, it's very great and helpful for other members of community who stuck in similar case.

    Have a nice day.

    Regards,
    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us