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. THE STRANGEST WM_TIMER ISSUE (only for gurus)

THE STRANGEST WM_TIMER ISSUE (only for gurus)

Scheduled Pinned Locked Moved C / C++ / MFC
cssgraphicsdata-structureshelpquestion
8 Posts 3 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.
  • D Offline
    D Offline
    Daniel Visan
    wrote on last edited by
    #1

    Somewhere: "SetTimer(1,10,0);" 10 means the function below is called in every "10 miliseconds" void CDDDView::OnTimer(UINT nIDEvent) { if (nIDEvent==1) { //draw a bitmap in different points to simulate an animation } } 10 miliseconds is too less for a Pentium II ,so the bitmap cant redraw at every 10 miliseconds. NOW, THE EXCITING PART: I have a CTreeCtrl in my view. When i move the mouse over the tree the bitmap redraw 3 times faster!!!!!!!!! Is there a guru on Earth to explain this??? :confused: PS: if somebody wants to see the application i'll send by e-mail. It is my graduated project. Sorry for not a good English.

    T 1 Reply Last reply
    0
    • D Daniel Visan

      Somewhere: "SetTimer(1,10,0);" 10 means the function below is called in every "10 miliseconds" void CDDDView::OnTimer(UINT nIDEvent) { if (nIDEvent==1) { //draw a bitmap in different points to simulate an animation } } 10 miliseconds is too less for a Pentium II ,so the bitmap cant redraw at every 10 miliseconds. NOW, THE EXCITING PART: I have a CTreeCtrl in my view. When i move the mouse over the tree the bitmap redraw 3 times faster!!!!!!!!! Is there a guru on Earth to explain this??? :confused: PS: if somebody wants to see the application i'll send by e-mail. It is my graduated project. Sorry for not a good English.

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      > "SetTimer(1,10,0);" 10 means the function below is called in > every "10 miliseconds" No. Windows timers use INT 8 interrupt internally, which fires at 18.2 Hz. The minimal elapsed time is about 55 ms, even if you pass 10 to SetTimer. And, OnTimer is not guaranteed to be called when time elapses - WM_TIMER messages are posted to the message queue and have the lowest priority. Tomasz Sowinski -- http://www.shooltz.com

      D 1 Reply Last reply
      0
      • T Tomasz Sowinski

        > "SetTimer(1,10,0);" 10 means the function below is called in > every "10 miliseconds" No. Windows timers use INT 8 interrupt internally, which fires at 18.2 Hz. The minimal elapsed time is about 55 ms, even if you pass 10 to SetTimer. And, OnTimer is not guaranteed to be called when time elapses - WM_TIMER messages are posted to the message queue and have the lowest priority. Tomasz Sowinski -- http://www.shooltz.com

        D Offline
        D Offline
        Daniel Visan
        wrote on last edited by
        #3

        Ok! Ok! I think i didn't make myself clear! In my view derived class i have a bitmap who redraws in VM_TIMER handle.I have a tree control, and a multiline edit control too. Normaly, the bitmap move on the screen with a speed lets say "x". WHEN I MOVE THE MOUSE OVER THE TREE CONTROL, OR WHEN I SELECT THE TEXT WITHIN A MULTIEDIT CONTROL (FROM MY CView DERIVED CLASS) THE BITMAP MOVES WITH A SPEED "3*x". I KNOW THIS SOUNDS WEIRD! Why? Why? Why?

        T 1 Reply Last reply
        0
        • D Daniel Visan

          Ok! Ok! I think i didn't make myself clear! In my view derived class i have a bitmap who redraws in VM_TIMER handle.I have a tree control, and a multiline edit control too. Normaly, the bitmap move on the screen with a speed lets say "x". WHEN I MOVE THE MOUSE OVER THE TREE CONTROL, OR WHEN I SELECT THE TEXT WITHIN A MULTIEDIT CONTROL (FROM MY CView DERIVED CLASS) THE BITMAP MOVES WITH A SPEED "3*x". I KNOW THIS SOUNDS WEIRD! Why? Why? Why?

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          The Windows scheduler boosts the priority of the thread that owns the window, when a window receives input, such as timer messages, mouse messages, or keyboard input. Priority boost gives more processor time and your bitmap is redrawn faster. BTW: Do you really think that SCREAMING makes you more readable? Tomasz Sowinski -- http://www.shooltz.com

          D 1 Reply Last reply
          0
          • T Tomasz Sowinski

            The Windows scheduler boosts the priority of the thread that owns the window, when a window receives input, such as timer messages, mouse messages, or keyboard input. Priority boost gives more processor time and your bitmap is redrawn faster. BTW: Do you really think that SCREAMING makes you more readable? Tomasz Sowinski -- http://www.shooltz.com

            D Offline
            D Offline
            Daniel Visan
            wrote on last edited by
            #5

            And how comes in the following cases the bitmap doesn't move faster and implicitly Windows scheduler doesnt boost the priority of my thread? 1)Put all my fingers on the keyboard. 2)Click the mouse 5 times a second OUT OF THE TREE and OUT OF THE EDIT CONTROL. Does Windows scheduler boost the priority of my thread ONLY when my view receives messages from the child windows? How can you explain that? For you it seems all right. For me not. Sorry for screaming.:((

            T 1 Reply Last reply
            0
            • D Daniel Visan

              And how comes in the following cases the bitmap doesn't move faster and implicitly Windows scheduler doesnt boost the priority of my thread? 1)Put all my fingers on the keyboard. 2)Click the mouse 5 times a second OUT OF THE TREE and OUT OF THE EDIT CONTROL. Does Windows scheduler boost the priority of my thread ONLY when my view receives messages from the child windows? How can you explain that? For you it seems all right. For me not. Sorry for screaming.:((

              T Offline
              T Offline
              Tomasz Sowinski
              wrote on last edited by
              #6

              > And how comes in the following cases the bitmap doesn't move > faster and implicitly Windows scheduler doesnt boost the > priority of my thread? I have no idea - maybe your WM_KEYDOWN handler is glacially slow. You can use Performance Monitor to check what's going on with the priority base/boost. Anyway, if you want smoothly animated bitmap in your program, you'll have to create a separate "painter" thread. Tomasz Sowinski -- http://www.shooltz.com

              J 1 Reply Last reply
              0
              • T Tomasz Sowinski

                > And how comes in the following cases the bitmap doesn't move > faster and implicitly Windows scheduler doesnt boost the > priority of my thread? I have no idea - maybe your WM_KEYDOWN handler is glacially slow. You can use Performance Monitor to check what's going on with the priority base/boost. Anyway, if you want smoothly animated bitmap in your program, you'll have to create a separate "painter" thread. Tomasz Sowinski -- http://www.shooltz.com

                J Offline
                J Offline
                Justin Hallet
                wrote on last edited by
                #7

                The problem is when you move your mouse, you are probably causing a an invalidate on the tree control, which means you are forcing events to repaint you window, this will be as fast as you pc can handle. SetTimer ( ... ) & OnTimer ( ... )== 55 milli seconds is the fasters you can do. Now using an idle loop you can go as fast as you like (Idle Loop Processing in MSDN) BOOL bDoingBackgroundProcessing = TRUE; while ( bDoingBackgroundProcessing ) { MSG msg; while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) { if ( !PumpMessage( ) ) { bDoingBackgroundProcessing = FALSE; ::PostQuitMessage( ); break; } } // let MFC do its idle processing LONG lIdle = 0; while ( AfxGetApp()->OnIdle(lIdle++ ) ) { // Do nothing } // Now you can check if at least 10 ms have passed if so do paint, if not loop }

                T 1 Reply Last reply
                0
                • J Justin Hallet

                  The problem is when you move your mouse, you are probably causing a an invalidate on the tree control, which means you are forcing events to repaint you window, this will be as fast as you pc can handle. SetTimer ( ... ) & OnTimer ( ... )== 55 milli seconds is the fasters you can do. Now using an idle loop you can go as fast as you like (Idle Loop Processing in MSDN) BOOL bDoingBackgroundProcessing = TRUE; while ( bDoingBackgroundProcessing ) { MSG msg; while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) { if ( !PumpMessage( ) ) { bDoingBackgroundProcessing = FALSE; ::PostQuitMessage( ); break; } } // let MFC do its idle processing LONG lIdle = 0; while ( AfxGetApp()->OnIdle(lIdle++ ) ) { // Do nothing } // Now you can check if at least 10 ms have passed if so do paint, if not loop }

                  T Offline
                  T Offline
                  Tomasz Sowinski
                  wrote on last edited by
                  #8

                  > The problem is when you move your mouse, you are probably > causing a an invalidate on the tree control It's not the default Windows behavior. Tree control isn't invalidated when mouse moves over it, even with TVS_TRACKSELECT style set, unless application calls InvalidateRect 'manually' in response to WM_MOUSEMOVE. Tomasz Sowinski -- http://www.shooltz.com

                  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