[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Closing application



> How can I catch the event that closes the application by clicking on the
> Close icon in the top right corner ?
> I've tryied to catch the M_EXIT in the cmd window but it doesn't work.
>
> If I have an exit option that generates the M_EXIT event then fine (if I
> use that option form the menu) but not by 'Alt-F4' or the icon.

You need to override
> void myApp::Exit(void)
and/or 
> int myApp::CloseAppWin(vWindow* win)
The first one controls the closing of the whole application, and the second
one controls the closing of a window (under Windos, if it is an SDI
application, this is the same thing, but for MDI it's different, at least
you are closing the last window).

The default behaviour of Exit() is to call CloseAppWin for all open windows,
so just call vApp::Exit() in your overriden function if you really want to
exit, or do "return" otherwise.

The default behaviour of CloseAppWin(win) is to close the window "win", so
just do "return vApp::CloseAppWin(win)" if you really want to close the
window, or "return 0" otherwise.

I think it is better to override both, since it seems to me that on X it is
CloseAppWin which is called when you close the window (the unique one, it's
something like SDI) via window manager, but on Win it is Exit which is
called. So when I didn't override Exit, but only CloseAppWin I had some
problems on windows, and in the inverse case on X.  Also, I overrided both.
If you like, take a look on a piece of my code.

>
> void myApp::Exit(void)
> {
>     if (ExitDisabled)                             //
>     {                                             //
>	myNoticeDialog note(this);                  // This is my clsosing
>	note.Notice("You can not exit now !!!");    // controle code.
>	return;                                     //
>     }                                             //
>     vApp::Exit();
> }
>
> int myApp::CloseAppWin(vWindow* win)
> {
>     myCmdWindow* cw = (myCmdWindow*)win;
>     if (ExitDisabled)                             // Note that this is an
>     {                                             // exact repetition of the
>	myNoticeDialog note(this);                  // code from Exit().
>	note.Notice("You can not exit now !!!");    // Writing it two times
>	return 0;                                   // let my program to work
>     }                                             // both on X and Win.
>     else
>     {
>	return vApp::CloseAppWin(win);
>     }
> }
>

Hope this helps.

Regards,
                        Serguei.
___________________________________________________________________________
Serguei DACHIAN
Laboratoire de Statistique et Processus,
Universite du Maine, Av. Olivier Messiaen
72085 Le Mans CEDEX 9, FRANCE
Tel.   : +33 (0)2 43 83 37 18
Fax.   : +33 (0)2 43 83 35 79
E-mail : Serguei.Dachian@univ-lemans.fr
WWW    : http://www.univ-lemans.fr/sciences/statist/cvs/thesard.html#dachian


Reply to: