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. Is there an equivalent to SuspendLayout/ResumeLayout for a MFC Dialog ?

Is there an equivalent to SuspendLayout/ResumeLayout for a MFC Dialog ?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++question
20 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 abiemann

    The controls still flicker :-( my overall process is: //Dialog - prevent changes from being redrawn this->SetRedraw(FALSE); //invert parts of static image onthe Dialog, behind the controls pDC = this->GetDC(); targetDC.CreateCompatibleDC(pDC); pOldTargetBmp = targetDC.SelectObject(&m_BmpTarget); targetDC.PatBlt(X,Y,iWidth,iHeight,DSTINVERT); targetDC.SelectObject(pOldTargetBmp); targetDC.DeleteDC(); ReleaseDC(pDC); m_DialogStaticImage.SetBitmap(HBITMAP(m_BmpTarget)); //redraw all controls to put them into foreground m_staticText.RedrawWindow(NULL,NULL,RDW_UPDATENOW); m_editBox.RedrawWindow(NULL,NULL,RDW_FRAME+RDW_INVALIDATE+RDW_UPDATENOW); . . about 15 controls . //Dialog - allow changes to be redrawn this->SetRedraw(TRUE); //no need to erase background since SetBitmap covered everything up this->Invalidate(FALSE); //show updated Dialog this->UpdateWindow(); I was surprised that it would still flicker; I was hoping that all the graphics operations were done in memory, then simply shown when UpdateWindow was called - thus avoiding flicker.

    M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #8

    abiemann wrote:

    I was surprised that it would still flicker; I was hoping that all the graphics operations were done in memory, then simply shown when UpdateWindow was called - thus avoiding flicker.

    Nope.  Looking more closely at your code, the only way you'll be able to prevent flicker is to do the drawing offscreen yourself, then blt the whole thing to the dialog. Mark

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    A 1 Reply Last reply
    0
    • M Mark Salsbery

      abiemann wrote:

      I was surprised that it would still flicker; I was hoping that all the graphics operations were done in memory, then simply shown when UpdateWindow was called - thus avoiding flicker.

      Nope.  Looking more closely at your code, the only way you'll be able to prevent flicker is to do the drawing offscreen yourself, then blt the whole thing to the dialog. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      A Offline
      A Offline
      abiemann
      wrote on last edited by
      #9

      Indeed, I was hoping that SetRedraw would implement double-buffering easily... but I found a good CP link that I'm studying now: http://www.codeproject.com/gdi/flicker\_free\_intro.asp EDIT: I've compiled the "flicker free" project under VS8 and I see that the "Draw Area" flickers.

      1 Reply Last reply
      0
      • A abiemann

        The controls still flicker :-( my overall process is: //Dialog - prevent changes from being redrawn this->SetRedraw(FALSE); //invert parts of static image onthe Dialog, behind the controls pDC = this->GetDC(); targetDC.CreateCompatibleDC(pDC); pOldTargetBmp = targetDC.SelectObject(&m_BmpTarget); targetDC.PatBlt(X,Y,iWidth,iHeight,DSTINVERT); targetDC.SelectObject(pOldTargetBmp); targetDC.DeleteDC(); ReleaseDC(pDC); m_DialogStaticImage.SetBitmap(HBITMAP(m_BmpTarget)); //redraw all controls to put them into foreground m_staticText.RedrawWindow(NULL,NULL,RDW_UPDATENOW); m_editBox.RedrawWindow(NULL,NULL,RDW_FRAME+RDW_INVALIDATE+RDW_UPDATENOW); . . about 15 controls . //Dialog - allow changes to be redrawn this->SetRedraw(TRUE); //no need to erase background since SetBitmap covered everything up this->Invalidate(FALSE); //show updated Dialog this->UpdateWindow(); I was surprised that it would still flicker; I was hoping that all the graphics operations were done in memory, then simply shown when UpdateWindow was called - thus avoiding flicker.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #10

        abiemann wrote:

        //no need to erase background since SetBitmap covered everything up this->Invalidate(FALSE);

        You have a static control that is used to display a bitmap. Yes? Is it overlapping the other controls such that they are requiring this?


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        A 1 Reply Last reply
        0
        • D David Crow

          abiemann wrote:

          //no need to erase background since SetBitmap covered everything up this->Invalidate(FALSE);

          You have a static control that is used to display a bitmap. Yes? Is it overlapping the other controls such that they are requiring this?


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          A Offline
          A Offline
          abiemann
          wrote on last edited by
          #11

          Yes, I have a static bitmap covering the entire Dialog window. Other controls (Buttons, Edit boxes) are ontop of this bitmap.

          D 1 Reply Last reply
          0
          • A abiemann

            Yes, I have a static bitmap covering the entire Dialog window. Other controls (Buttons, Edit boxes) are ontop of this bitmap.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #12

            So are you rendering this image in the dialog's OnEraseBkgnd() method?


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            A 1 Reply Last reply
            0
            • D David Crow

              So are you rendering this image in the dialog's OnEraseBkgnd() method?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              A Offline
              A Offline
              abiemann
              wrote on last edited by
              #13

              no I haven't touched the OnEraseBkgnd() or OnPaint methods. The code above is processed whenever the user presses a key or lets go of a key. (I haven't worked much with MFC, so I'm still learning)

              D 1 Reply Last reply
              0
              • A abiemann

                I love using SuspendLayout and ResumeLayout in .Net to avoid flicker, however, these don't seem to exist for an MFC Dialog. Is there an equivalent to use on my MFC Dialog ?

                W Offline
                W Offline
                Waldermort
                wrote on last edited by
                #14

                did you try the WS_CLIP_CHILDREN flag? This alone would reduce a hell of a lot of flicker.

                M A 2 Replies Last reply
                0
                • W Waldermort

                  did you try the WS_CLIP_CHILDREN flag? This alone would reduce a hell of a lot of flicker.

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #15

                  Good point!  For whatever reason, when I see bitmap background code I think skin, transparent controls, etc.  For normal controls WS_CLIPCHILDREN will work great! :) Cheers, Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  1 Reply Last reply
                  0
                  • A abiemann

                    no I haven't touched the OnEraseBkgnd() or OnPaint methods. The code above is processed whenever the user presses a key or lets go of a key. (I haven't worked much with MFC, so I'm still learning)

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #16

                    abiemann wrote:

                    no I haven't touched the OnEraseBkgnd()...

                    Put your bitmap-rendering code in there and note the difference.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    A 1 Reply Last reply
                    0
                    • D David Crow

                      abiemann wrote:

                      no I haven't touched the OnEraseBkgnd()...

                      Put your bitmap-rendering code in there and note the difference.


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      A Offline
                      A Offline
                      abiemann
                      wrote on last edited by
                      #17

                      Hi David, I've made the change and the background bitmap doesn't flicker at all, however, the controls ontop of the bitmap still flicker. This is the change I've made: KeyHandler now triggers OnEraseBkgnd instead of performing PatBlt When the user presses a key, the key's number is stored in a private member variable of the Dialog. To subsequently make it update the background image, the Dialogs' key handler performs : this->Invalidate(TRUE); this->UpdateWindow(); OnEraseBkgnd now does the PatBlt of the static image behind the controls Next, OnEraseBkgnd(CDC* pDC) is processed. this handler first checks that a key was pressed, if so, it performs the targetDC.PatBlt (I just use the pDC that's passed in) then it returns TRUE. If no key was pressed then I let this handler perform the default CDialog::OnEraseBkgnd(pDC) After this change I noticed that the individual controls no longer need their RedrawWindow() called, however, they still flicker (but the background static image doesn't flicker at all now). I've also removed the SetRedraw() calls -- modified at 19:14 Thursday 6th September, 2007

                      M D 2 Replies Last reply
                      0
                      • A abiemann

                        Hi David, I've made the change and the background bitmap doesn't flicker at all, however, the controls ontop of the bitmap still flicker. This is the change I've made: KeyHandler now triggers OnEraseBkgnd instead of performing PatBlt When the user presses a key, the key's number is stored in a private member variable of the Dialog. To subsequently make it update the background image, the Dialogs' key handler performs : this->Invalidate(TRUE); this->UpdateWindow(); OnEraseBkgnd now does the PatBlt of the static image behind the controls Next, OnEraseBkgnd(CDC* pDC) is processed. this handler first checks that a key was pressed, if so, it performs the targetDC.PatBlt (I just use the pDC that's passed in) then it returns TRUE. If no key was pressed then I let this handler perform the default CDialog::OnEraseBkgnd(pDC) After this change I noticed that the individual controls no longer need their RedrawWindow() called, however, they still flicker (but the background static image doesn't flicker at all now). I've also removed the SetRedraw() calls -- modified at 19:14 Thursday 6th September, 2007

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #18

                        Did you try adding the WS_CLIPCHILDREN style to the dialog as suggested by WalderMort? Mark

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        1 Reply Last reply
                        0
                        • A abiemann

                          Hi David, I've made the change and the background bitmap doesn't flicker at all, however, the controls ontop of the bitmap still flicker. This is the change I've made: KeyHandler now triggers OnEraseBkgnd instead of performing PatBlt When the user presses a key, the key's number is stored in a private member variable of the Dialog. To subsequently make it update the background image, the Dialogs' key handler performs : this->Invalidate(TRUE); this->UpdateWindow(); OnEraseBkgnd now does the PatBlt of the static image behind the controls Next, OnEraseBkgnd(CDC* pDC) is processed. this handler first checks that a key was pressed, if so, it performs the targetDC.PatBlt (I just use the pDC that's passed in) then it returns TRUE. If no key was pressed then I let this handler perform the default CDialog::OnEraseBkgnd(pDC) After this change I noticed that the individual controls no longer need their RedrawWindow() called, however, they still flicker (but the background static image doesn't flicker at all now). I've also removed the SetRedraw() calls -- modified at 19:14 Thursday 6th September, 2007

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #19

                          In other words, it works but it doesn't work. :confused:


                          "A good athlete is the result of a good and worthy opponent." - David Crow

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          1 Reply Last reply
                          0
                          • W Waldermort

                            did you try the WS_CLIP_CHILDREN flag? This alone would reduce a hell of a lot of flicker.

                            A Offline
                            A Offline
                            abiemann
                            wrote on last edited by
                            #20

                            I've tried the following within ::OnInitDialog() this->ModifyStyle(0, WS_CLIPCHILDREN); but then nothing in the Dialog updates

                            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