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. Working with Timers

Working with Timers

Scheduled Pinned Locked Moved C / C++ / MFC
question
18 Posts 5 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.
  • V Offline
    V Offline
    VinayCool
    wrote on last edited by
    #1

    Hi, I have a timer which was working proeprly before adding threads, now i have added thread funtion after that timer is not displayed on the dialog window can anyone tell me what is the cause ..... ------------------------------------------- BOOL CStatusDlg::OnInitDialog() { CDialog::OnInitDialog(); HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0); return TRUE; } --------------------------------------------------- UINT WorkerThreadProc(LPVOID Param) { CStatusDlg* status = (CStatusDlg *)Param; time(&lStartTime); SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); INDX.startIndex(); return true; } ------------------------------------------------------ void CStatusDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if(nIDEvent == ELAPSED_TIMER) { time(&lStopTime); cteElapsedTime = CTimeSpan(lStopTime-lStartTime); CString csElapsedTime; csElapsedTime.Format("%02d:%02d:%02d", cteElapsedTime.GetHours(), cteElapsedTime.GetMinutes(), cteElapsedTime.GetSeconds()); if(IsWindowVisible()) { m_TIME.SetWindowText(csElapsedTime); } } CDialog::OnTimer(nIDEvent); } ----------------------------------------------------------------- :) Regards, Vinay Charan.

    M D 2 Replies Last reply
    0
    • V VinayCool

      Hi, I have a timer which was working proeprly before adding threads, now i have added thread funtion after that timer is not displayed on the dialog window can anyone tell me what is the cause ..... ------------------------------------------- BOOL CStatusDlg::OnInitDialog() { CDialog::OnInitDialog(); HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0); return TRUE; } --------------------------------------------------- UINT WorkerThreadProc(LPVOID Param) { CStatusDlg* status = (CStatusDlg *)Param; time(&lStartTime); SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); INDX.startIndex(); return true; } ------------------------------------------------------ void CStatusDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if(nIDEvent == ELAPSED_TIMER) { time(&lStopTime); cteElapsedTime = CTimeSpan(lStopTime-lStartTime); CString csElapsedTime; csElapsedTime.Format("%02d:%02d:%02d", cteElapsedTime.GetHours(), cteElapsedTime.GetMinutes(), cteElapsedTime.GetSeconds()); if(IsWindowVisible()) { m_TIME.SetWindowText(csElapsedTime); } } CDialog::OnTimer(nIDEvent); } ----------------------------------------------------------------- :) Regards, Vinay Charan.

      M Offline
      M Offline
      Michel Wassink
      wrote on last edited by
      #2

      I think the thread does not know to which dialog the timer belongs.:doh: try change: SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); to: status->SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); Michel Wassink


      We must make user friendly software. Where are friendly users?

      V 1 Reply Last reply
      0
      • M Michel Wassink

        I think the thread does not know to which dialog the timer belongs.:doh: try change: SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); to: status->SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); Michel Wassink


        We must make user friendly software. Where are friendly users?

        V Offline
        V Offline
        VinayCool
        wrote on last edited by
        #3

        Hi Michel Wassink, I tryed as u said i am getting below error status->SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); error C2660: 'SetTimer' : function does not take 4 parameters Error executing cl.exe.

        M T 2 Replies Last reply
        0
        • V VinayCool

          Hi Michel Wassink, I tryed as u said i am getting below error status->SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); error C2660: 'SetTimer' : function does not take 4 parameters Error executing cl.exe.

          M Offline
          M Offline
          Michel Wassink
          wrote on last edited by
          #4

          Sorry, my fault.:zzz: choose between: status->SetTimer(ELAPSED_TIMER, 1000, NULL); or SetTimer(status->m_hWnd,ELAPSED_TIMER, 1000, NULL); Michel Wassink


          We must make user friendly software. Where are friendly users?

          V 2 Replies Last reply
          0
          • M Michel Wassink

            Sorry, my fault.:zzz: choose between: status->SetTimer(ELAPSED_TIMER, 1000, NULL); or SetTimer(status->m_hWnd,ELAPSED_TIMER, 1000, NULL); Michel Wassink


            We must make user friendly software. Where are friendly users?

            V Offline
            V Offline
            VinayCool
            wrote on last edited by
            #5

            Hi Michel Wassink, It's working fine thank you very much.. I have one more problem with timer can u please tell me how to stop the timer??? timer which i have added does not stop.

            M 1 Reply Last reply
            0
            • V VinayCool

              Hi Michel Wassink, I tryed as u said i am getting below error status->SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); error C2660: 'SetTimer' : function does not take 4 parameters Error executing cl.exe.

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              vinaycool wrote:

              status->SetTimer(NULL,ELAPSED_TIMER, 1000, NULL);

              do this :- status->SetTimer(ELAPSED_TIMER, 1000, NULL);

              "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

              V 1 Reply Last reply
              0
              • T ThatsAlok

                vinaycool wrote:

                status->SetTimer(NULL,ELAPSED_TIMER, 1000, NULL);

                do this :- status->SetTimer(ELAPSED_TIMER, 1000, NULL);

                "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

                V Offline
                V Offline
                VinayCool
                wrote on last edited by
                #7

                Hi, This is working fine for me SetTimer(status->m_hWnd,ELAPSED_TIMER, 1000, NULL); i want to know how to stop the timer ....

                T 1 Reply Last reply
                0
                • M Michel Wassink

                  Sorry, my fault.:zzz: choose between: status->SetTimer(ELAPSED_TIMER, 1000, NULL); or SetTimer(status->m_hWnd,ELAPSED_TIMER, 1000, NULL); Michel Wassink


                  We must make user friendly software. Where are friendly users?

                  V Offline
                  V Offline
                  VinayCool
                  wrote on last edited by
                  #8

                  Hi Michel Wassink, i tryed using KillTimer(ELAPSED_TIMER); error C2660: 'KillTimer' : function does not take 1 parameters Error executing cl.exe. can u please tell how to stop ....

                  1 Reply Last reply
                  0
                  • V VinayCool

                    Hi Michel Wassink, It's working fine thank you very much.. I have one more problem with timer can u please tell me how to stop the timer??? timer which i have added does not stop.

                    M Offline
                    M Offline
                    Michel Wassink
                    wrote on last edited by
                    #9

                    Use KillTimer(ELAPSED_TIMER); to stop the timer. Michel Wassink


                    We must make user friendly software. Where are friendly users?

                    V 1 Reply Last reply
                    0
                    • M Michel Wassink

                      Use KillTimer(ELAPSED_TIMER); to stop the timer. Michel Wassink


                      We must make user friendly software. Where are friendly users?

                      V Offline
                      V Offline
                      VinayCool
                      wrote on last edited by
                      #10

                      Hi, I used KillTimer(ELAPSED_TIMER); i got error C2660: 'KillTimer' : function does not take 1 parameters Error executing cl.exe. then i used KillTimer(NULL,ELAPSED_TIMER); then no error but timer is not stoping please give me some solution.

                      M 1 Reply Last reply
                      0
                      • V VinayCool

                        Hi, This is working fine for me SetTimer(status->m_hWnd,ELAPSED_TIMER, 1000, NULL); i want to know how to stop the timer ....

                        T Offline
                        T Offline
                        ThatsAlok
                        wrote on last edited by
                        #11

                        vinaycool wrote:

                        This is working fine for meSetTimer(status->m_hWnd,ELAPSED_TIMER, 1000, NULL);i want to know how to stop the timer ....

                        Ok, KillTimer(..) will stop the timer

                        "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

                        V 1 Reply Last reply
                        0
                        • T ThatsAlok

                          vinaycool wrote:

                          This is working fine for meSetTimer(status->m_hWnd,ELAPSED_TIMER, 1000, NULL);i want to know how to stop the timer ....

                          Ok, KillTimer(..) will stop the timer

                          "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

                          V Offline
                          V Offline
                          VinayCool
                          wrote on last edited by
                          #12

                          hi, I tryed using KillTimer(ELAPSED_TIMER); but i am getting error error C2660: 'KillTimer' : function does not take 1 parameters Error executing cl.exe.

                          R T 2 Replies Last reply
                          0
                          • V VinayCool

                            Hi, I used KillTimer(ELAPSED_TIMER); i got error C2660: 'KillTimer' : function does not take 1 parameters Error executing cl.exe. then i used KillTimer(NULL,ELAPSED_TIMER); then no error but timer is not stoping please give me some solution.

                            M Offline
                            M Offline
                            Michel Wassink
                            wrote on last edited by
                            #13

                            from within the thread: status->KillTimer(ELAPSED_TIMER); or KillTimer(status->m_hWnd, ELAPSED_TIMER); Michel Wassink


                            We must make user friendly software. Where are friendly users?

                            V 1 Reply Last reply
                            0
                            • M Michel Wassink

                              from within the thread: status->KillTimer(ELAPSED_TIMER); or KillTimer(status->m_hWnd, ELAPSED_TIMER); Michel Wassink


                              We must make user friendly software. Where are friendly users?

                              V Offline
                              V Offline
                              VinayCool
                              wrote on last edited by
                              #14

                              Hi Michel Wassink, KillTimer(status->m_hWnd, ELAPSED_TIMER); is working thank you very much..................:)

                              1 Reply Last reply
                              0
                              • V VinayCool

                                hi, I tryed using KillTimer(ELAPSED_TIMER); but i am getting error error C2660: 'KillTimer' : function does not take 1 parameters Error executing cl.exe.

                                R Offline
                                R Offline
                                Roger Stoltz
                                wrote on last edited by
                                #15

                                Since you're using the raw API call, you have to provide it with the window handle the same way you called ::SetTimer().


                                _It's supposed to be hard, otherwise anybody could do it!

                                Regarding CodeProject: "resistance is pointless; you will be assimilated"_

                                V 1 Reply Last reply
                                0
                                • V VinayCool

                                  hi, I tryed using KillTimer(ELAPSED_TIMER); but i am getting error error C2660: 'KillTimer' : function does not take 1 parameters Error executing cl.exe.

                                  T Offline
                                  T Offline
                                  ThatsAlok
                                  wrote on last edited by
                                  #16

                                  vinaycool wrote:

                                  KillTimer(ELAPSED_TIMER);but i am getting error

                                  what about KillTImer(status->m_hWnd,ELAPSED_TIMER)

                                  "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

                                  1 Reply Last reply
                                  0
                                  • R Roger Stoltz

                                    Since you're using the raw API call, you have to provide it with the window handle the same way you called ::SetTimer().


                                    _It's supposed to be hard, otherwise anybody could do it!

                                    Regarding CodeProject: "resistance is pointless; you will be assimilated"_

                                    V Offline
                                    V Offline
                                    VinayCool
                                    wrote on last edited by
                                    #17

                                    Hi, Thanks for the information it will be usefull for me.

                                    1 Reply Last reply
                                    0
                                    • V VinayCool

                                      Hi, I have a timer which was working proeprly before adding threads, now i have added thread funtion after that timer is not displayed on the dialog window can anyone tell me what is the cause ..... ------------------------------------------- BOOL CStatusDlg::OnInitDialog() { CDialog::OnInitDialog(); HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0); return TRUE; } --------------------------------------------------- UINT WorkerThreadProc(LPVOID Param) { CStatusDlg* status = (CStatusDlg *)Param; time(&lStartTime); SetTimer(NULL,ELAPSED_TIMER, 1000, NULL); INDX.startIndex(); return true; } ------------------------------------------------------ void CStatusDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if(nIDEvent == ELAPSED_TIMER) { time(&lStopTime); cteElapsedTime = CTimeSpan(lStopTime-lStartTime); CString csElapsedTime; csElapsedTime.Format("%02d:%02d:%02d", cteElapsedTime.GetHours(), cteElapsedTime.GetMinutes(), cteElapsedTime.GetSeconds()); if(IsWindowVisible()) { m_TIME.SetWindowText(csElapsedTime); } } CDialog::OnTimer(nIDEvent); } ----------------------------------------------------------------- :) Regards, Vinay Charan.

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

                                      vinaycool wrote:

                                      hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0);

                                      Since this is an MFC application, why are you not using AfxBeginThread() here.


                                      "The largest fire starts but with the smallest spark." - David Crow

                                      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