Announcement

Collapse
No announcement yet.

Dialog Redraw vs Control Redraw - flicker reduction

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dialog Redraw vs Control Redraw - flicker reduction

    I'm just beginning to look at controlling flicker when resizing a dialog.

    I wrote a simple app with two image controls and put a picture in each.

    Then I used %WM_SIZE to trigger resizing the controls. The resizing works fine but the use of Dialog Redraw gives MUCH more noticeable flicker than using a redraw for each of the two controls I placed on the dialog.

    Code:
              Dialog Redraw hDlg
    vs
              Control ReDraw hDlg, 110
              Control ReDraw hDlg, 120
    This is the opposite of what Help says - which is that Control Redraw schedules a redraw whereas Dialog Redraw gives immediate results.

    Is there a general rule about using redraw commands, or more likely a body of experience on the topic to get flicker free resizing of controls on a dialog.

    I did a brief forum search on flicker, but most posts didn't seem to address the question, although I must admit I didn't search long and hard.

    Here's the whole example, if it's needed. I used one of my PBR files to get an image for the imagex controls.

    Code:
       #Compile Exe
       #Include "Win32API.inc"
       #Resource "pb-test.pbr"
       Global hDlg As Dword, hLst As Dword, hTemp As Dword
       Global style&, extstyle&
       Function PBMain() As Long
        Dialog New Pixels, 0, "Graphic Control Test",300,300,450,380, _
                                  %WS_OverlappedWindow, 0 To hDlg
    
        style& = %WS_Visible Or %SS_Notify
        Control Add ImageX, hDlg, 110,"cowgirl", 0,0,200,300, style&
        Control Add ImageX, hDlg, 120,"cowgirl", 210,0,200,300, style&
        Dialog Show Modal hDlg Call DlgProc
       End Function
    
       CallBack Function DlgProc() As Long
          If Cb.Msg = %WM_Size Then
              Dim w As Long, h As Long   'width/height of dialog
              Dialog Get Client hDlg To w,h
    
              Control Set Size hDlg, 110, w/2-4, h
    
              Control Set Size hDlg, 120, w/2-4, h
              Control Set Loc hDlg, 120, w/2+4, 0
    
    '          Dialog ReDraw hDlg
              Control ReDraw hDlg, 110
              Control ReDraw hDlg, 120
          End If
        End Function
    Last edited by Gary Beene; 16 Feb 2009, 01:26 AM.

  • #2
    Hello Gary. Try using WS_CLIPCHILDREN in the creation of your dialog, flicker will be gone.

    Comment


    • #3
      I think Elias already gave you the right indication: use %WS_CLIPCHILDREN style in your DIALOG NEW ... statement. It is a simple solution to many flickering problems.

      Also, I would suggest to avoid to redraw your controls (or dialog) in response to a %WM_SIZE event. Thare is almost always another way to do it.

      Ciao
      Eros
      thinBasic programming language
      Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

      Comment


      • #4
        Originally posted by Eros Olmi View Post
        Also, I would suggest to avoid to redraw your controls (or dialog) in response to a %WM_SIZE event.
        Why should this be avoided Eros?

        Comment


        • #5
          Mainly to avoid flickering.

          When you resize a control, a redraw message is already sent to you control. The same when you resize a dialog. So if you fire another redraw you are just redrawing all twice.

          I'm not an expert of MS documentation. I just say it on top of my personal experience so I can be wrong.
          thinBasic programming language
          Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

          Comment


          • #6
            Originally posted by Eros Olmi View Post
            Mainly to avoid flickering.

            When you resize a control, a redraw message is already sent to you control. The same when you resize a dialog. So if you fire another redraw you are just redrawing all twice.
            Thanks Eros!

            Comment


            • #7
              Flicker and the use of WS_CLIPCHILDREN described here - http://www.catch22.net/content/flicker-free-drawing
              Rgds, Dave

              Comment


              • #8
                Elias,

                Thanks for the tip. I tried it and it is much better, with both the Dialog and Control redraws. I read the Help entry on it, but since I wasn't using %WS_THICKFRAME - which Help gave as a possible complicating factor, I didn't give it a try.

                Eros,

                I also saw that warning in the PB Help file, but when I did it anyway nothing bad seemed to happen. When I saw the warning I assumed the problem would have been an unending series of redraw, but didn't see it. Why would it only be 2, as your comment noted? I guess I could test it easily enough with a static counter, unless there are timing issues which make the answer different every time. Especiially with multiple redraws, I can see why flickering would be a risk.

                If I'm using the mouse to resize the dialog, and want the image updated realtime, what message other than %WM_SIZE is available that I should use to REDRAW? If I wait for a mouseup, then I don't get a realtime update to the dialog content.

                Dave,
                Thanks for the link. I did a quick read and it has good information. I'll go back and absorb the details.

                Comment


                • #9
                  Actually, I was using %WS_OVERLAPPEDWINDOW, whose value includes %WS_THICKFRAME. So Help actually gave me a clue to a fix if I had just understood it!

                  Comment

                  Working...
                  X