Working with Timers
-
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.
-
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.
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?
-
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?
-
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.
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?
-
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?
-
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.
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
-
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
-
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?
-
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.
Use KillTimer(ELAPSED_TIMER); to stop the timer. Michel Wassink
We must make user friendly software. Where are friendly users?
-
Use KillTimer(ELAPSED_TIMER); to stop the timer. Michel Wassink
We must make user friendly software. Where are friendly users?
-
Hi, This is working fine for me SetTimer(status->m_hWnd,ELAPSED_TIMER, 1000, NULL); i want to know how to stop the timer ....
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
-
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
-
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.
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?
-
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?
-
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.
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"_
-
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.
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
-
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"_
-
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.
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