OnTimer function is killed automatically when the dialog is closed
-
Hi friends, When i close the dialog that time OnTimer function is automaticaly killed. I dont know what is the reason behind this. For your information this dialog is added in the PropertySheet. Normally, if dialog is closed also the onTimer function keep run.. But i my case OnTimer function is get killed. Dialog contain CaptureOn and CaptureOff button. when captureOn button is pressed that time SetTime function get invoked and CapStopWatch function is called, to calculate and display time(like stopwatch) and when i press the CaptureOff button then timer get killed. If i press CaptureOn button and close the dialog that time OnTimer function automatically get killed. When same dialog invoked after, OnTimer called automatically, and its operate every slower(more than 1000 to 2000) but Initially i called set timer function with 100millisecond and i given code for your reference.
void CReplay::OnCaptureOn()
{
CapWatchID = SetTimer(CAP_STOPWATCH, 100, TIMERPROC);
}
void CReplay::OnTimer(UINT nIDEvent)
{
if(CapWatchID)
{
CapStopWatch();
}
}void CReplay::CapStopWatch()
{
CString sTime;
static clock_t tThisTime;
static int TempSec=0;
static int idelay=0;tThisTime = clock();
dMin1++;
if(dMin1 == 10)
{
double TimeDiff = (double) ( tThisTime - tSimTime ) / CLOCKS_PER_SEC;
TempSec = (int)TimeDiff;if( TempSec >= 60 ) { niSec++; tSimTime = clock(); } else niSec++; if( niSec >= 60 ) { nMin++; niSec -= 60; } if( nMin >= 60 )
{
nHr++;
nTotHr++;
nMin -= 60;
tSimTime = clock();
}sTime.Format("%02d:%02d:%02d",nHr,nMin,niSec); iHrEnd = iCurHr= nHr; iMinEnd = iCurMin= nMin; iSecEnd = iCurSec = niSec; if(CaptureRunning == 1) { m\_CaptureSW.SetFont(&StopWatchFont); m\_CaptureSW.SetWindowText(sTime); } else if(ReplayRunning =1) { m\_Elapsed.SetFont(&StopWatchFont); m\_Elapsed.SetWindowText(sTime); }
}
if(nHr==12)
nHr=0;
}if(dMin1 >= 10)
dMin1 =0;
}Kindly help me friends... Regards S.Shanmugaraja.
-
Hi friends, When i close the dialog that time OnTimer function is automaticaly killed. I dont know what is the reason behind this. For your information this dialog is added in the PropertySheet. Normally, if dialog is closed also the onTimer function keep run.. But i my case OnTimer function is get killed. Dialog contain CaptureOn and CaptureOff button. when captureOn button is pressed that time SetTime function get invoked and CapStopWatch function is called, to calculate and display time(like stopwatch) and when i press the CaptureOff button then timer get killed. If i press CaptureOn button and close the dialog that time OnTimer function automatically get killed. When same dialog invoked after, OnTimer called automatically, and its operate every slower(more than 1000 to 2000) but Initially i called set timer function with 100millisecond and i given code for your reference.
void CReplay::OnCaptureOn()
{
CapWatchID = SetTimer(CAP_STOPWATCH, 100, TIMERPROC);
}
void CReplay::OnTimer(UINT nIDEvent)
{
if(CapWatchID)
{
CapStopWatch();
}
}void CReplay::CapStopWatch()
{
CString sTime;
static clock_t tThisTime;
static int TempSec=0;
static int idelay=0;tThisTime = clock();
dMin1++;
if(dMin1 == 10)
{
double TimeDiff = (double) ( tThisTime - tSimTime ) / CLOCKS_PER_SEC;
TempSec = (int)TimeDiff;if( TempSec >= 60 ) { niSec++; tSimTime = clock(); } else niSec++; if( niSec >= 60 ) { nMin++; niSec -= 60; } if( nMin >= 60 )
{
nHr++;
nTotHr++;
nMin -= 60;
tSimTime = clock();
}sTime.Format("%02d:%02d:%02d",nHr,nMin,niSec); iHrEnd = iCurHr= nHr; iMinEnd = iCurMin= nMin; iSecEnd = iCurSec = niSec; if(CaptureRunning == 1) { m\_CaptureSW.SetFont(&StopWatchFont); m\_CaptureSW.SetWindowText(sTime); } else if(ReplayRunning =1) { m\_Elapsed.SetFont(&StopWatchFont); m\_Elapsed.SetWindowText(sTime); }
}
if(nHr==12)
nHr=0;
}if(dMin1 >= 10)
dMin1 =0;
}Kindly help me friends... Regards S.Shanmugaraja.
A timer should be killed when the window that calls
SetTimer()
is closed / destroyed. If you need a timer that is also running when specific dialogs are not active, you should use it from within other windows like your main frame window. -
Hi friends, When i close the dialog that time OnTimer function is automaticaly killed. I dont know what is the reason behind this. For your information this dialog is added in the PropertySheet. Normally, if dialog is closed also the onTimer function keep run.. But i my case OnTimer function is get killed. Dialog contain CaptureOn and CaptureOff button. when captureOn button is pressed that time SetTime function get invoked and CapStopWatch function is called, to calculate and display time(like stopwatch) and when i press the CaptureOff button then timer get killed. If i press CaptureOn button and close the dialog that time OnTimer function automatically get killed. When same dialog invoked after, OnTimer called automatically, and its operate every slower(more than 1000 to 2000) but Initially i called set timer function with 100millisecond and i given code for your reference.
void CReplay::OnCaptureOn()
{
CapWatchID = SetTimer(CAP_STOPWATCH, 100, TIMERPROC);
}
void CReplay::OnTimer(UINT nIDEvent)
{
if(CapWatchID)
{
CapStopWatch();
}
}void CReplay::CapStopWatch()
{
CString sTime;
static clock_t tThisTime;
static int TempSec=0;
static int idelay=0;tThisTime = clock();
dMin1++;
if(dMin1 == 10)
{
double TimeDiff = (double) ( tThisTime - tSimTime ) / CLOCKS_PER_SEC;
TempSec = (int)TimeDiff;if( TempSec >= 60 ) { niSec++; tSimTime = clock(); } else niSec++; if( niSec >= 60 ) { nMin++; niSec -= 60; } if( nMin >= 60 )
{
nHr++;
nTotHr++;
nMin -= 60;
tSimTime = clock();
}sTime.Format("%02d:%02d:%02d",nHr,nMin,niSec); iHrEnd = iCurHr= nHr; iMinEnd = iCurMin= nMin; iSecEnd = iCurSec = niSec; if(CaptureRunning == 1) { m\_CaptureSW.SetFont(&StopWatchFont); m\_CaptureSW.SetWindowText(sTime); } else if(ReplayRunning =1) { m\_Elapsed.SetFont(&StopWatchFont); m\_Elapsed.SetWindowText(sTime); }
}
if(nHr==12)
nHr=0;
}if(dMin1 >= 10)
dMin1 =0;
}Kindly help me friends... Regards S.Shanmugaraja.
Without seeing some of your code it is impossible to guess what may be happening. Where is your timer created and where is it destroyed?
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Hi friends, When i close the dialog that time OnTimer function is automaticaly killed. I dont know what is the reason behind this. For your information this dialog is added in the PropertySheet. Normally, if dialog is closed also the onTimer function keep run.. But i my case OnTimer function is get killed. Dialog contain CaptureOn and CaptureOff button. when captureOn button is pressed that time SetTime function get invoked and CapStopWatch function is called, to calculate and display time(like stopwatch) and when i press the CaptureOff button then timer get killed. If i press CaptureOn button and close the dialog that time OnTimer function automatically get killed. When same dialog invoked after, OnTimer called automatically, and its operate every slower(more than 1000 to 2000) but Initially i called set timer function with 100millisecond and i given code for your reference.
void CReplay::OnCaptureOn()
{
CapWatchID = SetTimer(CAP_STOPWATCH, 100, TIMERPROC);
}
void CReplay::OnTimer(UINT nIDEvent)
{
if(CapWatchID)
{
CapStopWatch();
}
}void CReplay::CapStopWatch()
{
CString sTime;
static clock_t tThisTime;
static int TempSec=0;
static int idelay=0;tThisTime = clock();
dMin1++;
if(dMin1 == 10)
{
double TimeDiff = (double) ( tThisTime - tSimTime ) / CLOCKS_PER_SEC;
TempSec = (int)TimeDiff;if( TempSec >= 60 ) { niSec++; tSimTime = clock(); } else niSec++; if( niSec >= 60 ) { nMin++; niSec -= 60; } if( nMin >= 60 )
{
nHr++;
nTotHr++;
nMin -= 60;
tSimTime = clock();
}sTime.Format("%02d:%02d:%02d",nHr,nMin,niSec); iHrEnd = iCurHr= nHr; iMinEnd = iCurMin= nMin; iSecEnd = iCurSec = niSec; if(CaptureRunning == 1) { m\_CaptureSW.SetFont(&StopWatchFont); m\_CaptureSW.SetWindowText(sTime); } else if(ReplayRunning =1) { m\_Elapsed.SetFont(&StopWatchFont); m\_Elapsed.SetWindowText(sTime); }
}
if(nHr==12)
nHr=0;
}if(dMin1 >= 10)
dMin1 =0;
}Kindly help me friends... Regards S.Shanmugaraja.
I assume you talk about MFC and CWnd::OnTimer()? If so, what you describe is how I would expect it to work. That function and CWnd::SetTimer is a thin layer on the Win API ::SetTimer function and WM_TIMER message, where ::SetTimer is called with CWnd::m_hWnd as first arg. If you want the timer to continue after the window is destroyed, why don't you just call ::SetTimer directly with a NULL hWnd and a TIMERPROC? That way your timer will run as long as the thread runs or until you destroy it with a call to ::KilllTimer.
-
Without seeing some of your code it is impossible to guess what may be happening. Where is your timer created and where is it destroyed?
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
Dialog contain CaptureOn and CaptureOff button. when captureOn button is pressed that time SetTime function get invoked and CapStopWatch function is called, to calculate and display time(like stopwatch) and when i press the CaptureOff button then timer get killed. If i press CaptureOn button and close the dialog that time OnTimer function automatically get killed. When same dialog invoked after, OnTimer called automatically, and its operate every slower(more than 1000 to 2000) but Initially i called set timer function with 100millisecond and i given code for your reference. void CReplay::OnCaptureOn() { CapWatchID = SetTimer(CAP_STOPWATCH, 100, TIMERPROC); } void CReplay::OnTimer(UINT nIDEvent) { if(CapWatchID) { CapStopWatch(); } } void CReplay::CapStopWatch() { CString sTime; static clock_t tThisTime; static int TempSec=0; static int idelay=0; tThisTime = clock(); dMin1++; if(dMin1 == 10) { double TimeDiff = (double) ( tThisTime - tSimTime ) / CLOCKS_PER_SEC; TempSec = (int)TimeDiff; if( TempSec >= 60 ) { niSec++; tSimTime = clock(); } else niSec++; if( niSec >= 60 ) { nMin++; niSec -= 60; } if( nMin >= 60 ) { nHr++; nTotHr++; nMin -= 60; tSimTime = clock(); } sTime.Format("%02d:%02d:%02d",nHr,nMin,niSec); iHrEnd = iCurHr= nHr; iMinEnd = iCurMin= nMin; iSecEnd = iCurSec = niSec; if(CaptureRunning == 1) { m_CaptureSW.SetFont(&StopWatchFont); m_CaptureSW.SetWindowText(sTime); } else if(ReplayRunning =1) { m_Elapsed.SetFont(&StopWatchFont); m_Elapsed.SetWindowText(sTime); } } if(nHr==12) nHr=0; } if(dMin1 >= 10) dMin1 =0; }
-
I assume you talk about MFC and CWnd::OnTimer()? If so, what you describe is how I would expect it to work. That function and CWnd::SetTimer is a thin layer on the Win API ::SetTimer function and WM_TIMER message, where ::SetTimer is called with CWnd::m_hWnd as first arg. If you want the timer to continue after the window is destroyed, why don't you just call ::SetTimer directly with a NULL hWnd and a TIMERPROC? That way your timer will run as long as the thread runs or until you destroy it with a call to ::KilllTimer.
Hi, how to create "TIMERPROC".. Right now my application is developed using MCF. can you provide me any example code that may help me to resolve my problem. Regrads, S.Shanmugaraja
-
Dialog contain CaptureOn and CaptureOff button. when captureOn button is pressed that time SetTime function get invoked and CapStopWatch function is called, to calculate and display time(like stopwatch) and when i press the CaptureOff button then timer get killed. If i press CaptureOn button and close the dialog that time OnTimer function automatically get killed. When same dialog invoked after, OnTimer called automatically, and its operate every slower(more than 1000 to 2000) but Initially i called set timer function with 100millisecond and i given code for your reference. void CReplay::OnCaptureOn() { CapWatchID = SetTimer(CAP_STOPWATCH, 100, TIMERPROC); } void CReplay::OnTimer(UINT nIDEvent) { if(CapWatchID) { CapStopWatch(); } } void CReplay::CapStopWatch() { CString sTime; static clock_t tThisTime; static int TempSec=0; static int idelay=0; tThisTime = clock(); dMin1++; if(dMin1 == 10) { double TimeDiff = (double) ( tThisTime - tSimTime ) / CLOCKS_PER_SEC; TempSec = (int)TimeDiff; if( TempSec >= 60 ) { niSec++; tSimTime = clock(); } else niSec++; if( niSec >= 60 ) { nMin++; niSec -= 60; } if( nMin >= 60 ) { nHr++; nTotHr++; nMin -= 60; tSimTime = clock(); } sTime.Format("%02d:%02d:%02d",nHr,nMin,niSec); iHrEnd = iCurHr= nHr; iMinEnd = iCurMin= nMin; iSecEnd = iCurSec = niSec; if(CaptureRunning == 1) { m_CaptureSW.SetFont(&StopWatchFont); m_CaptureSW.SetWindowText(sTime); } else if(ReplayRunning =1) { m_Elapsed.SetFont(&StopWatchFont); m_Elapsed.SetWindowText(sTime); } } if(nHr==12) nHr=0; } if(dMin1 >= 10) dMin1 =0; }
Please edit your previous message and put <pre> tags around your code; as it stands it's very difficult to understand.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Hi, how to create "TIMERPROC".. Right now my application is developed using MCF. can you provide me any example code that may help me to resolve my problem. Regrads, S.Shanmugaraja
Create a console app and put this code in to see how it works, then you can adapt "myOnTimer" and the call to ::SetTimer to your code.
#include <windows.h>
#include <iostream>void CALLBACK myOnTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD tickCount)
{
std::cout << "Timer. id = " << idEvent << ", tick = " << tickCount << std::endl;
}int main(int argc, char * argv[])
{
MSG msg;UINT_PTR timerId = ::SetTimer(0, 42, 1000, myOnTimer);
std::cout << "Timer set, id = " << timerId << std::endl;
// This is done by MFC in your application but needed for the example.
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
} -
Create a console app and put this code in to see how it works, then you can adapt "myOnTimer" and the call to ::SetTimer to your code.
#include <windows.h>
#include <iostream>void CALLBACK myOnTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD tickCount)
{
std::cout << "Timer. id = " << idEvent << ", tick = " << tickCount << std::endl;
}int main(int argc, char * argv[])
{
MSG msg;UINT_PTR timerId = ::SetTimer(0, 42, 1000, myOnTimer);
std::cout << "Timer set, id = " << timerId << std::endl;
// This is done by MFC in your application but needed for the example.
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}But I am get error when i try to implement UINT_PTR timerId = ::SetTimer(0, 42, 1000, myOnTimer); in MFC VS6 ErrorReport:
'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned long,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'
-
Hi, how to create "TIMERPROC".. Right now my application is developed using MCF. can you provide me any example code that may help me to resolve my problem. Regrads, S.Shanmugaraja
shanmugarajaa wrote:
how to create "TIMERPROC"..
It's in the docs: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644901(v=vs.85).aspx#creating_timer[^]
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
But I am get error when i try to implement UINT_PTR timerId = ::SetTimer(0, 42, 1000, myOnTimer); in MFC VS6 ErrorReport:
'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned long,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'
I wrote that example for VS 2008, looks like the callback signature has changed a little since VS6. Try to change it to
void __stdcall myOnTimer(HWND hwnd, unsigned int uMsg, unsigned int idEvent, DWORD tickCount)
{
// ...
}as the error message suggests. If you have an MSDN library with your VS then you should be able to find the correct callback function signature there. Maybe even an example.
-
I wrote that example for VS 2008, looks like the callback signature has changed a little since VS6. Try to change it to
void __stdcall myOnTimer(HWND hwnd, unsigned int uMsg, unsigned int idEvent, DWORD tickCount)
{
// ...
}as the error message suggests. If you have an MSDN library with your VS then you should be able to find the correct callback function signature there. Maybe even an example.
Thanks you so much.
-
I wrote that example for VS 2008, looks like the callback signature has changed a little since VS6. Try to change it to
void __stdcall myOnTimer(HWND hwnd, unsigned int uMsg, unsigned int idEvent, DWORD tickCount)
{
// ...
}as the error message suggests. If you have an MSDN library with your VS then you should be able to find the correct callback function signature there. Maybe even an example.
Hi code working good.. but I cant able to kill this timer... can you help to kill this call.. Regards, S.Shanmugaraja
-
Hi code working good.. but I cant able to kill this timer... can you help to kill this call.. Regards, S.Shanmugaraja
-
You just call ::KillTimer(0, timerId); where timerId is the timer id value you got back from ::SetTimer.
Thanks Thanks so much :)
-
You just call ::KillTimer(0, timerId); where timerId is the timer id value you got back from ::SetTimer.
Hi, I am beginner to MFC application. I need your suggestion to improve my skill in MFC. How you come know about __stdcall and other functionality of MFC. Any material you have been using? kindly share your views and ideas. It may help me to improve my MFC skills. I am looking forward your valuable suggestion. Regards, S.Shanmugaraja
-
You just call ::KillTimer(0, timerId); where timerId is the timer id value you got back from ::SetTimer.
Hi, I am Calling CapWatchID: = ::SetTimer(SetTimer(0, 42, 1000, CaptureStopWatchT); and after sometime I killed this running timer using ::KillTimer(0, CapWatchID);. But the problem is, when I start the same timer again then Updation time became lessthan 1000 millisecond. Why its happing like this. kindly help me to fix this problem. Regards, S.Shanmugaraja.
-
Hi, I am beginner to MFC application. I need your suggestion to improve my skill in MFC. How you come know about __stdcall and other functionality of MFC. Any material you have been using? kindly share your views and ideas. It may help me to improve my MFC skills. I am looking forward your valuable suggestion. Regards, S.Shanmugaraja
This is not MFC as such. SetTimer and KillTimer Windows system functions documented by Microsoft. http://msdn.microsoft.com/library/default.aspx[^] There are many good books and online resources on the subject of C++ programming, Windows system programming and MFC. I suggest you try searching the net for recommendations and book reviews.
-
Hi, I am Calling CapWatchID: = ::SetTimer(SetTimer(0, 42, 1000, CaptureStopWatchT); and after sometime I killed this running timer using ::KillTimer(0, CapWatchID);. But the problem is, when I start the same timer again then Updation time became lessthan 1000 millisecond. Why its happing like this. kindly help me to fix this problem. Regards, S.Shanmugaraja.