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. Invalidate rectangle

Invalidate rectangle

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsjsonquestion
10 Posts 4 Posters 8 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.
  • C Offline
    C Offline
    Calin Negru
    wrote on last edited by
    #1

    I’m trying to display an animated bitmap in a win32 application with GDIplus. Last time when I talked about this here I was told I should invalidate a rectangle to force the App to refresh/draw another frame. I’m trying to understand the theory for now. I will come up with code in a day or two if necessary. My question is do you create and invalidate between beginpaint and endpaint a rectangle that has no particular purpose or does it have to be a rectangle that actually does something. I’m having a difficult time understanding the connection between a rectangle and the rendering process of a win32 api window

    C L C 3 Replies Last reply
    0
    • C Calin Negru

      I’m trying to display an animated bitmap in a win32 application with GDIplus. Last time when I talked about this here I was told I should invalidate a rectangle to force the App to refresh/draw another frame. I’m trying to understand the theory for now. I will come up with code in a day or two if necessary. My question is do you create and invalidate between beginpaint and endpaint a rectangle that has no particular purpose or does it have to be a rectangle that actually does something. I’m having a difficult time understanding the connection between a rectangle and the rendering process of a win32 api window

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Roughly speaking, the invalidated rectagle will be redrawn in the next WM_PAINT call (other parts of the client area are not redrawn). So, if you need to update a portion of the client area then invalidate the corresponding rectangle and then call UpdateWindow(). In simple scenarios you can invalidate the entire client area and then call UpdateWindow(). See, for instance: Invalidating the Client Area - Win32 apps | Microsoft Learn[^].

      "In testa che avete, Signor di Ceprano?" -- Rigoletto

      C 1 Reply Last reply
      0
      • C CPallini

        Roughly speaking, the invalidated rectagle will be redrawn in the next WM_PAINT call (other parts of the client area are not redrawn). So, if you need to update a portion of the client area then invalidate the corresponding rectangle and then call UpdateWindow(). In simple scenarios you can invalidate the entire client area and then call UpdateWindow(). See, for instance: Invalidating the Client Area - Win32 apps | Microsoft Learn[^].

        "In testa che avete, Signor di Ceprano?" -- Rigoletto

        C Offline
        C Offline
        Calin Negru
        wrote on last edited by
        #3

        Basically I need a rectangle taking the whole window for my game, I think I understand, I’ll post a followup if I’ll run into trouble setting things. Thank you.

        C 1 Reply Last reply
        0
        • C Calin Negru

          Basically I need a rectangle taking the whole window for my game, I think I understand, I’ll post a followup if I’ll run into trouble setting things. Thank you.

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          You are welcome.

          "In testa che avete, Signor di Ceprano?" -- Rigoletto

          1 Reply Last reply
          0
          • C Calin Negru

            I’m trying to display an animated bitmap in a win32 application with GDIplus. Last time when I talked about this here I was told I should invalidate a rectangle to force the App to refresh/draw another frame. I’m trying to understand the theory for now. I will come up with code in a day or two if necessary. My question is do you create and invalidate between beginpaint and endpaint a rectangle that has no particular purpose or does it have to be a rectangle that actually does something. I’m having a difficult time understanding the connection between a rectangle and the rendering process of a win32 api window

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

            The only things you should be doing between BeginPaint and EndPaint is redrawing/rewriting the parts of the client window that may have changed. Outside of the WM_PAINT handler, you decide which part (or all) of the window needs to be repainted. You then set those values into a call to InvalidateRect, which will post a WM_PAINT message to your message queue.

            C 1 Reply Last reply
            0
            • L Lost User

              The only things you should be doing between BeginPaint and EndPaint is redrawing/rewriting the parts of the client window that may have changed. Outside of the WM_PAINT handler, you decide which part (or all) of the window needs to be repainted. You then set those values into a call to InvalidateRect, which will post a WM_PAINT message to your message queue.

              C Offline
              C Offline
              Calin Negru
              wrote on last edited by
              #6

              >The only things you should be doing between beginpaint and endpaint I was thinking to disregard everything that was rendered in one frame, and then render things all over again. Keeping track of pieces that visually change in my game ( if that’s what you mean) seems like a burden at this point. So far I’m only looking for a way to trigger a new paint event

              L 1 Reply Last reply
              0
              • C Calin Negru

                >The only things you should be doing between beginpaint and endpaint I was thinking to disregard everything that was rendered in one frame, and then render things all over again. Keeping track of pieces that visually change in my game ( if that’s what you mean) seems like a burden at this point. So far I’m only looking for a way to trigger a new paint event

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

                You are welcome to do that, but it may affect the performance in certain scenarios.

                C 1 Reply Last reply
                0
                • L Lost User

                  You are welcome to do that, but it may affect the performance in certain scenarios.

                  C Offline
                  C Offline
                  Calin Negru
                  wrote on last edited by
                  #8

                  I see

                  L 1 Reply Last reply
                  0
                  • C Calin Negru

                    I see

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

                    It all seems a bit odd until you understand that everything in Windows is message driven. For each message type that you handle you need an event handler, for all the others just let Windows deal with them.

                    1 Reply Last reply
                    0
                    • C Calin Negru

                      I’m trying to display an animated bitmap in a win32 application with GDIplus. Last time when I talked about this here I was told I should invalidate a rectangle to force the App to refresh/draw another frame. I’m trying to understand the theory for now. I will come up with code in a day or two if necessary. My question is do you create and invalidate between beginpaint and endpaint a rectangle that has no particular purpose or does it have to be a rectangle that actually does something. I’m having a difficult time understanding the connection between a rectangle and the rendering process of a win32 api window

                      C Offline
                      C Offline
                      charlieg
                      wrote on last edited by
                      #10

                      I might do some searching through CP. There are some excellent articles covering the madness of Windows drawing, GDI, etc. DCs, their variations and purposes are also covered pretty well. Just keep in mind the point behind InvalidateRectangle - GDI is somewhat smart. It will limit it's drawing to regions it knows it needs to re-draw which is why you need an InvalidateRectangle call.

                      Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

                      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