Re: Please help: How to close a application when specific time?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jase (jshelley_at_spamblock.enersol.com.au)
Date: 04/01/04


Date: Thu, 1 Apr 2004 16:13:26 +1000


"AA" <anthony@jadeflex.com> wrote in message
news:exV3Re6FEHA.580@TK2MSFTNGP11.phx.gbl...
> Dear sir,
> I try to write a MFC application that will automatically close at
> specific time.
> I use a OnTimer Event to check the time. If current time is equal to "exit
> time", the application will close automatically.
> But how to trigger the operation of "quit application"?
>
> I try to PostMessage(WM_QUIT) in the OnTimer Event. The application can
> quit successfully, but it don't call the OnCloseDocument() and the
> destructor of the document. SO, it have memory leak. How to quit it
> gracefully?
>
> Thanks
>
> --
> Regards,
>
> Anthony Lam
>

BTW PostQuitMessage(<exit code>) is no different to PostMessage(WM_QUIT,
<exit code>, 0), so I would expect the same result. Try
AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_APP_EXIT, 0); (fakes clicking
the exit button in the file menu).

Second thing is that you should use a waitable timer
(CreateWaitableTimer(...)), otherwise, if your computer is in hibernation,
it won't wake up to handle the timer, and so won't quit.

Jase



Relevant Pages

  • Re: CLISP [1]> ?
    ... Use the usual editing capabilities. ... or (exit) leaves CLISP. ...
    (comp.lang.lisp)
  • Re: Big Number Arithmetic
    ... This is free software with ABSOLUTELY NO WARRANTY. ... bash-2.05b# exit ... for help, \q to quit. ...
    (sci.crypt)
  • Booten auf entfernter Maschine sichern
    ... wo neben dem Upgrade auch schon einige Kernel-Updates ... will er das ja immer nach einigen Tagen Uptime machen. ... logically or'ed into the exit code. ...
    (de.comp.os.unix.linux.misc)
  • Re: tcl/tk on Windows: "This application has requested the Runtime to terminate it in an unusual way
    ... I assume you mean calling the 'exit' command. ... the proc 'quit' that you've written. ... Windows) as explicitly quitting Tk's even loop. ... explicitly destroy the root toplevel (a hint found via a google search, ...
    (comp.lang.tcl)
  • Re: for(;;) or while(1)?
    ... it is much better to use a condition to exit. ... >> if input is quit then die ... It says "loop until I am told to quit" instead of "loop ... function that kills your process and never have to exit your forever ...
    (comp.lang.c)