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. SetTimer, nIDEvent and timer identification

SetTimer, nIDEvent and timer identification

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
4 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
    Dimitris Vikeloudas
    wrote on last edited by
    #1

    I want to use timers do some actions. I read about UINT SetTimer(HWND hWnd, UINT nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc ); versus the CWnd::SetTimer, UINT nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc ); There is a nice document here explaining some facts. However, I still have some questions about who is handling the timers. I want to create and handle the timers inside a CScrollView (by mapping and overwriting the inherited CWnd::OnTimer(UINT nIDEvent) and not via a TIMERPROC. However, I am not sure which timer creation function to use and what value will be good for the nIDEvent on them. i. How do I guarantee that the CScrollView which created the timer is the one that receives the WM_TIMER message (and subsequently process it). Is it possible that the WM_TIMER expiration message ends up on another queue (I found that this is possible for mouse messages) or only the creating window can get it? ii. Is the nIDEvent identifier a system unique one or a view unique one? How do I get a sufficiently unique nIDEvent value to make sure that I am processing the right timer? iii. Is it possible that my CScrollView will receive time outs (i.e. WM_TIMER messages) by other views or even other threads or applications and under which conditions? If yes what should I do with those timers? iv. Any idea why SetTimer may fail? Is this due to a system limit on running timers or due to a non unique nIDEvent? How can I know? Dimitris

    K 1 Reply Last reply
    0
    • D Dimitris Vikeloudas

      I want to use timers do some actions. I read about UINT SetTimer(HWND hWnd, UINT nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc ); versus the CWnd::SetTimer, UINT nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc ); There is a nice document here explaining some facts. However, I still have some questions about who is handling the timers. I want to create and handle the timers inside a CScrollView (by mapping and overwriting the inherited CWnd::OnTimer(UINT nIDEvent) and not via a TIMERPROC. However, I am not sure which timer creation function to use and what value will be good for the nIDEvent on them. i. How do I guarantee that the CScrollView which created the timer is the one that receives the WM_TIMER message (and subsequently process it). Is it possible that the WM_TIMER expiration message ends up on another queue (I found that this is possible for mouse messages) or only the creating window can get it? ii. Is the nIDEvent identifier a system unique one or a view unique one? How do I get a sufficiently unique nIDEvent value to make sure that I am processing the right timer? iii. Is it possible that my CScrollView will receive time outs (i.e. WM_TIMER messages) by other views or even other threads or applications and under which conditions? If yes what should I do with those timers? iv. Any idea why SetTimer may fail? Is this due to a system limit on running timers or due to a non unique nIDEvent? How can I know? Dimitris

      K Offline
      K Offline
      Kurt _B
      wrote on last edited by
      #2

      i. If you do "this->SetTimer(100, 2000, NULL)" inside your CScrollView class it will use the handle for your view. ii. It is unique to your view. How many timers are you planning on using? If just one declare a constant. iii. Yes if some sends the WM_TIMER message to that view. Really shouldn't happen though. iv. How do you know it's failing?

      D 1 Reply Last reply
      0
      • K Kurt _B

        i. If you do "this->SetTimer(100, 2000, NULL)" inside your CScrollView class it will use the handle for your view. ii. It is unique to your view. How many timers are you planning on using? If just one declare a constant. iii. Yes if some sends the WM_TIMER message to that view. Really shouldn't happen though. iv. How do you know it's failing?

        D Offline
        D Offline
        Dimitris Vikeloudas
        wrote on last edited by
        #3

        Thanks a lot. It clarifies a lot of things. Thus, I can be sure that my view and only this will handle the timers. My plans are to use one timer primarely but there are some rare cases that I may have two running similtaneously. However, if their ids are view unique ones I can use constants to guarantee uniquness and I am assuming that noone sends to my view a WM_TIMER message (according to what you said it sounds a reasonable assumption. Note that the thread will have more than one CScroll views of the same or different type). According to my reading SetTimer indicates failure if it returns zero. Thus, I know that it is failed to create a timer. But it seems to me that this is due to system resources limits thus, nothing that I can do about it. Well, was quite helpfull clarifying these points, hope now that they will work like these. Dimitris...

        L 1 Reply Last reply
        0
        • D Dimitris Vikeloudas

          Thanks a lot. It clarifies a lot of things. Thus, I can be sure that my view and only this will handle the timers. My plans are to use one timer primarely but there are some rare cases that I may have two running similtaneously. However, if their ids are view unique ones I can use constants to guarantee uniquness and I am assuming that noone sends to my view a WM_TIMER message (according to what you said it sounds a reasonable assumption. Note that the thread will have more than one CScroll views of the same or different type). According to my reading SetTimer indicates failure if it returns zero. Thus, I know that it is failed to create a timer. But it seems to me that this is due to system resources limits thus, nothing that I can do about it. Well, was quite helpfull clarifying these points, hope now that they will work like these. Dimitris...

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

          Hello, do you have: ON_WM_TIMER() in your Messagemap included?? than you have to call the function like this: // but befor call OnTimer you have first set the timer in some other funktion: int SomeOtherFunc() { nIDEvent = SetTimer(iTimerIdentifier, iIntervalMiliSecond,0); //iTimerIdentifier is stored in nIDEvent for use in OnTimer(UINT nIDEvent), iIntervalMiliSecond is the time to wait between intervals // example nIDEvent = SetTimer(2, 1000,0); } afx_msg void MyAppDlg::OnTimer(UINT nIDEvent) { // do something with this nIDEvent switch(nIDEvent) { case 1: { ... break; } case 2: { // in my example the OnTimer jump here, and i can do something ... ... break; } //etc. default: break; } } .... give peace of code to see what you coding to set and start timer! break; -- modified at 11:13 Wednesday 19th July, 2006

          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