Click to See Complete Forum and Search --> : How to close an application using a timer event!
Sascha W.
August 31st, 1999, 03:54 AM
I want to close my application using a timer event (the application should kill itself). The timer is initialised and works, so what code do I have to write in the timer event routine? I tried things like OnClose(), OnDestroy() but then I got always an error message if I run the application. What did I forgot?
Thanks and regards
Sascha
Jörg Eckart
August 31st, 1999, 03:58 AM
Hi,
I think you should send a WM_CLOSE-Message with SendMessage.
Bye, Jörg
Dietmar
August 31st, 1999, 08:05 AM
Try this:
OnTimer(UINT nIDEvent)
{
m_counter++;
if (m_counter>=m_end)
{
KillTimer(1);
exit(1);
}
}
Add int m_counter to as a member variable and initialize it with zero in OnInitDialog() or OnInitInstance(). m_end is the amount of timer ticks before your app should exit. Start the timer by:
SetTimer(1,1000,NULL);
and m_end is the number of seconds before your app ends.
Fabi Pantera
August 31st, 1999, 08:18 AM
AfxGetMainWnd()->SendMessage(WM_CLOSE, NULL, NULL)
Let me know if this helps you.
Best regards,
Faby
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.