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. Using InvalidateRect to force screen update

Using InvalidateRect to force screen update

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++questionannouncement
10 Posts 5 Posters 1 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.
  • M Offline
    M Offline
    mortishroom
    wrote on last edited by
    #1

    Hi! I'm new to programming in VC+++, maybe someone here could help me out.Im using an 'InvalidateRect' in my application's 'OnIdle' message handler and it is returning an error. here is the code : InvalidateRect( hwnd, NULL, TRUE); and the error: hwnd : undeclared identifier hwnd seems to be a pointer to the main window? do I have to define it?

    D P T 3 Replies Last reply
    0
    • M mortishroom

      Hi! I'm new to programming in VC+++, maybe someone here could help me out.Im using an 'InvalidateRect' in my application's 'OnIdle' message handler and it is returning an error. here is the code : InvalidateRect( hwnd, NULL, TRUE); and the error: hwnd : undeclared identifier hwnd seems to be a pointer to the main window? do I have to define it?

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

      mortishroom wrote: hwnd seems to be a pointer to the main window? Probably a window handle, rather than a pointer. mortishroom wrote: do I have to define it? Not to pacify the compiler, but it must be declared. At runtime, it must be defined with a valid value.


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      1 Reply Last reply
      0
      • M mortishroom

        Hi! I'm new to programming in VC+++, maybe someone here could help me out.Im using an 'InvalidateRect' in my application's 'OnIdle' message handler and it is returning an error. here is the code : InvalidateRect( hwnd, NULL, TRUE); and the error: hwnd : undeclared identifier hwnd seems to be a pointer to the main window? do I have to define it?

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        Are you using MFC or win32, The api that you are calling is of win32. For win32 api you need to have a valid window handle to send the notification to. if you are using MFC then first parameter is not required. In win32 you can use IsWindow(HWND) api to check wheather the hWnd is valid or not. Since you say you are biggener, You should check in ur code wheather you are creating any window, if so are you storing the pointer somewhere else. In Windows, The ui are targeted for certain function or api using the windows handle. Simple speaking you need a valide windows handle to call the above api. Hope i clear ur problem.


        "Fear not of those who can kill the body and not the soul, rather fear Him who can kill both body and soul" - Bible Prakash, India.

        M 1 Reply Last reply
        0
        • P Prakash Nadar

          Are you using MFC or win32, The api that you are calling is of win32. For win32 api you need to have a valid window handle to send the notification to. if you are using MFC then first parameter is not required. In win32 you can use IsWindow(HWND) api to check wheather the hWnd is valid or not. Since you say you are biggener, You should check in ur code wheather you are creating any window, if so are you storing the pointer somewhere else. In Windows, The ui are targeted for certain function or api using the windows handle. Simple speaking you need a valide windows handle to call the above api. Hope i clear ur problem.


          "Fear not of those who can kill the body and not the soul, rather fear Him who can kill both body and soul" - Bible Prakash, India.

          M Offline
          M Offline
          mortishroom
          wrote on last edited by
          #4

          Mr.Prakash wrote: Are you using MFC or win32, The api that you are calling is of win32. Im using MFC w/the vc++ mfc app wizard. passing it NULL instead ov hWind worked just fine. thank you.

          P 1 Reply Last reply
          0
          • M mortishroom

            Mr.Prakash wrote: Are you using MFC or win32, The api that you are calling is of win32. Im using MFC w/the vc++ mfc app wizard. passing it NULL instead ov hWind worked just fine. thank you.

            P Offline
            P Offline
            Prakash Nadar
            wrote on last edited by
            #5

            Strange, dont know how it works, I need to go back to books to understand that. Is it really working the way you are expecting it?? If you dont mind try replaying the NULL with m_hWnd its a predifined window handle in MFC.


            "Fear not of those who can kill the body and not the soul, rather fear Him who can kill both body and soul" - Bible Prakash, India.

            M 1 Reply Last reply
            0
            • P Prakash Nadar

              Strange, dont know how it works, I need to go back to books to understand that. Is it really working the way you are expecting it?? If you dont mind try replaying the NULL with m_hWnd its a predifined window handle in MFC.


              "Fear not of those who can kill the body and not the soul, rather fear Him who can kill both body and soul" - Bible Prakash, India.

              M Offline
              M Offline
              mortishroom
              wrote on last edited by
              #6

              'm_hWnd' gives me an undeclared identifier error. Null is working exactly how i expected; and my code refreshes the screen at 90 million mph, causing everything to flicker uncontrollably. I geuss the next thing i need to learn is about 'frame rate'. :)

              R 1 Reply Last reply
              0
              • M mortishroom

                'm_hWnd' gives me an undeclared identifier error. Null is working exactly how i expected; and my code refreshes the screen at 90 million mph, causing everything to flicker uncontrollably. I geuss the next thing i need to learn is about 'frame rate'. :)

                R Offline
                R Offline
                Robert A T Kaldy
                wrote on last edited by
                #7

                1. If you pass InvalidateRect(NULL, rect), it invalidates all application windows. So I don't wonder, that it flickers. 2. Where are you calling the InvalidateRect from? Generally, in MFC you must retrieve a pointer to redrawn window (CWnd*) and then call CWnd::InvalidateRect(CRect rc, BOOL erase). You needn't to deal with HWND's. Robert-Antonio "CRAY is the only computer, which runs an endless loop in just 4 hours"

                M 1 Reply Last reply
                0
                • M mortishroom

                  Hi! I'm new to programming in VC+++, maybe someone here could help me out.Im using an 'InvalidateRect' in my application's 'OnIdle' message handler and it is returning an error. here is the code : InvalidateRect( hwnd, NULL, TRUE); and the error: hwnd : undeclared identifier hwnd seems to be a pointer to the main window? do I have to define it?

                  T Offline
                  T Offline
                  Terry ONolley
                  wrote on last edited by
                  #8

                  You can just use this->Invalidate(TRUE); from within the window you want to repaint's loop.


                  Have you answered an MTQ? Check out the stats!
                  What's the latest butt-scratch count? Check it out!

                  M 1 Reply Last reply
                  0
                  • R Robert A T Kaldy

                    1. If you pass InvalidateRect(NULL, rect), it invalidates all application windows. So I don't wonder, that it flickers. 2. Where are you calling the InvalidateRect from? Generally, in MFC you must retrieve a pointer to redrawn window (CWnd*) and then call CWnd::InvalidateRect(CRect rc, BOOL erase). You needn't to deal with HWND's. Robert-Antonio "CRAY is the only computer, which runs an endless loop in just 4 hours"

                    M Offline
                    M Offline
                    mortishroom
                    wrote on last edited by
                    #9

                    a pointer? hmm. thanks for the info - I'll have to look into it next time I get a chance.

                    1 Reply Last reply
                    0
                    • T Terry ONolley

                      You can just use this->Invalidate(TRUE); from within the window you want to repaint's loop.


                      Have you answered an MTQ? Check out the stats!
                      What's the latest butt-scratch count? Check it out!

                      M Offline
                      M Offline
                      mortishroom
                      wrote on last edited by
                      #10

                      this->Invalidate(TRUE); gives me 'Invalidate' : is not a member of 'CMyApp'. I think I am calling it in the wrong place. how do I access one object's members from another object?

                      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