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. InvalidateRect and GDI

InvalidateRect and GDI

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphicshelpdiscussion
12 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.
  • T ThatsAlok

    LighthouseJ wrote: Can I only invalidate one rectangle specified by a couple CRect structures at a time? yes I believe!

    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

    cheers, Alok Gupta VC Forum Q&A :- I/ IV

    L Offline
    L Offline
    LighthouseJ
    wrote on last edited by
    #3

    See, I have code like this: if (first test statement) { (update data) (invalidate one rectangle) } if (second test statement) { (update other data) (invalidate another rectangle) } and both sections work independantly as far as what it tests for. The first if statement is run several times more than the second, but I let my program run and something I didn't expect to happens. What happens is that the screen is updated whenever the second statement is run (less often), but both the first and second rectangle are refreshed (with erases). I tried switching the order of the if statements but it still refreshes at the frequency of the lesser used if statement rectangle invalidation. I don't know what to do about it, right now at least.

    J J 2 Replies Last reply
    0
    • L LighthouseJ

      See, I have code like this: if (first test statement) { (update data) (invalidate one rectangle) } if (second test statement) { (update other data) (invalidate another rectangle) } and both sections work independantly as far as what it tests for. The first if statement is run several times more than the second, but I let my program run and something I didn't expect to happens. What happens is that the screen is updated whenever the second statement is run (less often), but both the first and second rectangle are refreshed (with erases). I tried switching the order of the if statements but it still refreshes at the frequency of the lesser used if statement rectangle invalidation. I don't know what to do about it, right now at least.

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #4

      I'm not sure I understood your problem, but keep in mind that invalidating just means that it will be updated in then next paint cycle. If you want to make sure the window gets updated after each 'invalidate' you should also call UpdateWindow right after calling InvalidateRect -- jlr http://jlamas.blogspot.com/[^]

      L 1 Reply Last reply
      0
      • J Jose Lamas Rios

        I'm not sure I understood your problem, but keep in mind that invalidating just means that it will be updated in then next paint cycle. If you want to make sure the window gets updated after each 'invalidate' you should also call UpdateWindow right after calling InvalidateRect -- jlr http://jlamas.blogspot.com/[^]

        L Offline
        L Offline
        LighthouseJ
        wrote on last edited by
        #5

        I tried that by doing something like this: bool bUpdateWindow = false; CWnd * pParent = ::AfxGetMainWnd(); if (first test) { (change data) pParent->InvalidateRect(pRect1, true); bUpdateWindow = true; } if (second test) { (change other data) pParent->InvalidateRect(pRect2, true); bUpdateWindow = true; } if (bUpdateWindow) { pParent->UpdateWindow(); } But the behavior isn't changed from before.

        J 1 Reply Last reply
        0
        • L LighthouseJ

          I tried that by doing something like this: bool bUpdateWindow = false; CWnd * pParent = ::AfxGetMainWnd(); if (first test) { (change data) pParent->InvalidateRect(pRect1, true); bUpdateWindow = true; } if (second test) { (change other data) pParent->InvalidateRect(pRect2, true); bUpdateWindow = true; } if (bUpdateWindow) { pParent->UpdateWindow(); } But the behavior isn't changed from before.

          J Offline
          J Offline
          Jose Lamas Rios
          wrote on last edited by
          #6

          Are you sure it's AfxGetMainWnd() the window you need to invalidate? What kind of window is the main one? Is it a dialog, MDI/SDI frame, or something else? -- jlr http://jlamas.blogspot.com/[^]

          L 1 Reply Last reply
          0
          • J Jose Lamas Rios

            Are you sure it's AfxGetMainWnd() the window you need to invalidate? What kind of window is the main one? Is it a dialog, MDI/SDI frame, or something else? -- jlr http://jlamas.blogspot.com/[^]

            L Offline
            L Offline
            LighthouseJ
            wrote on last edited by
            #7

            hmm, well I'm invalidating and updating the window in a thread... you raise an interesting question. The main window, in the file mainfrm.cpp, is CMainFrame, derived from CFrameWnd. Am I calling it's routines instead of the child and that's what's not right?

            J 1 Reply Last reply
            0
            • L LighthouseJ

              hmm, well I'm invalidating and updating the window in a thread... you raise an interesting question. The main window, in the file mainfrm.cpp, is CMainFrame, derived from CFrameWnd. Am I calling it's routines instead of the child and that's what's not right?

              J Offline
              J Offline
              Jose Lamas Rios
              wrote on last edited by
              #8

              I don't think invalidating CMainFrame would work, because it's unlikely CMainFrame is drawing something based on the data you change. You should be invalidating the specific window that needs to be updated. Better yet, if that's a CView-derived window, you should put the data in a document, modify the data using a document member function, which should call UpdateAllViews. Your view, in its OnUpdate member should invalidate and update itself based on that notification. -- jlr http://jlamas.blogspot.com/[^]

              L 1 Reply Last reply
              0
              • J Jose Lamas Rios

                I don't think invalidating CMainFrame would work, because it's unlikely CMainFrame is drawing something based on the data you change. You should be invalidating the specific window that needs to be updated. Better yet, if that's a CView-derived window, you should put the data in a document, modify the data using a document member function, which should call UpdateAllViews. Your view, in its OnUpdate member should invalidate and update itself based on that notification. -- jlr http://jlamas.blogspot.com/[^]

                L Offline
                L Offline
                LighthouseJ
                wrote on last edited by
                #9

                I'm trying to figure out a way to pass the instruction through from thread->CMainFrame(derived from CFrameWnd)->CChildView(derived from CWnd). There's no CView-derived thing in my project. I tried creating a message to pass but that's not working and I tried creating a function in CMainFrame to update the child view when it's called so the thread can call that, but it gives me access violations and it has question marks next to the values for the different window handles. I'm still checking it out.

                J 1 Reply Last reply
                0
                • L LighthouseJ

                  See, I have code like this: if (first test statement) { (update data) (invalidate one rectangle) } if (second test statement) { (update other data) (invalidate another rectangle) } and both sections work independantly as far as what it tests for. The first if statement is run several times more than the second, but I let my program run and something I didn't expect to happens. What happens is that the screen is updated whenever the second statement is run (less often), but both the first and second rectangle are refreshed (with erases). I tried switching the order of the if statements but it still refreshes at the frequency of the lesser used if statement rectangle invalidation. I don't know what to do about it, right now at least.

                  J Offline
                  J Offline
                  James Brown
                  wrote on last edited by
                  #10

                  When you invalidate a rectangle/region, this area does not get updated straight away. It will get updated the next time Windows decides to send your app a WM_PAINT message. To force an update after you invalidate a region, call the UpdateWindow API James
                  http://www.catch22.net

                  1 Reply Last reply
                  0
                  • L LighthouseJ

                    I'm trying to figure out a way to pass the instruction through from thread->CMainFrame(derived from CFrameWnd)->CChildView(derived from CWnd). There's no CView-derived thing in my project. I tried creating a message to pass but that's not working and I tried creating a function in CMainFrame to update the child view when it's called so the thread can call that, but it gives me access violations and it has question marks next to the values for the different window handles. I'm still checking it out.

                    J Offline
                    J Offline
                    Jose Lamas Rios
                    wrote on last edited by
                    #11

                    If you are in a worker thread you can't make direct calls to CWnd objects created in the main (GUI) thread. Instead, you need to pass a window handle (HWND) to the thread function and use it there to send or post private messages (WM_USER + n) from the worker thread to that window. -- jlr http://jlamas.blogspot.com/[^]

                    L 1 Reply Last reply
                    0
                    • J Jose Lamas Rios

                      If you are in a worker thread you can't make direct calls to CWnd objects created in the main (GUI) thread. Instead, you need to pass a window handle (HWND) to the thread function and use it there to send or post private messages (WM_USER + n) from the worker thread to that window. -- jlr http://jlamas.blogspot.com/[^]

                      L Offline
                      L Offline
                      LighthouseJ
                      wrote on last edited by
                      #12

                      This thread is a user-interface thread, I overrode CWinThread and pass the runtime class name to AfxBeginThread just as the documentation say you're supposed to do for a user-interface thread. I was trying to figure out a way to use messages but maybe I don't know as much as I need to. I defined a message like: #define WM_UPDATECHILD (WM_APP + 1) And tried to create a handler function for that message but it would never be run. I tried to override PreTranslateMessage, OnCmdMsg, and OnCommand to intercept this message, handle it, then return a nonzero result to show it was handled and none of this worked. I just don't know what to do.

                      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