CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 1999
    Location
    Nuernberg / Germany
    Posts
    80

    How to close an application using a timer event!

    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


  2. #2
    Join Date
    May 1999
    Posts
    35

    Re: How to close an application using a timer event!

    Hi,

    I think you should send a WM_CLOSE-Message with SendMessage.

    Bye, Jörg


  3. #3
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    64

    Re: How to close an application using a timer event!

    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.


  4. #4
    Join Date
    Jun 1999
    Posts
    319

    Re: How to close an application using a timer event!

    AfxGetMainWnd()->SendMessage(WM_CLOSE, NULL, NULL)
    Let me know if this helps you.
    Best regards,
    Faby


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured