Store Open Windows Properties at App Quit time ?

I want to store some preferences * at application quit time.

What I see to use are Window.Close and App.Close (I will not use CancelClose) events.

Why am I asking ?
Because I can close one window (or two or…), but stay with the application running.

How can I make the difference betwen Window.Close and App.Close ? As far as I understand, in App.Close, all windows have been closed, and at WIndow.Close time, I do not know if this is a user close action or App.Close.

  • Imagine I have two open windows, the user choose to quit, I want to save these two windows Rects, and Listbox StringWidth (one in each window).

Emile,

you can solve problems like that on your own. Really. Don’t save when quitting but when the window moves.

[code]Public Sub Constructor(ParentWindow as window, WindowTitle as string)

'save the position of the parentWindow

Globals.thePrefs.SetPrefNumber WindowTitle + “_Top”, ParentWindow.top
Globals.thePrefs.SetPrefNumber WindowTitle + “_Left”, ParentWindow.Left

'if the size of the window can be changed
if ParentWindow.Resizeable then
Globals.thePrefs.SetPrefNumber WindowTitle + “_Width”, ParentWindow.Width
Globals.thePrefs.SetPrefNumber WindowTitle + “_Height”, ParentWindow.Height
end if

exception exc
theException = new ErrorException(exc, currentMethodName)
End Sub
[/code]

I’ll leave the more complex loading of the values to you. You will need to check if the monitor has changed resolution etc.

Before a window Close event the window’s CancelClose event is raised. CancelClose has one Boolean parameter called appQuitting, which tells you if only this window is about to be closed or if the application is shutting down.

Thank you Beatrix, Eli for your informations.

I do not wanted to CancelClose the window, and so I do not check that event. What a mistake !

I wanted to throw my MacBook Pro through the window when I read Window.CancelClose !!!

BTW: I searched in App and Application before starting this conversation…

My fault: instead of searching (hat I think is) the obvious, I’d better search the weird or unexpected :wink:
(weird or unexpected: DC or Marvel comic books references)

I was starting to put code in the first window (in Close event) to save the data window in its own file in a dedicated folder: one line for each kind of data I want to store / (later) restore.

Then I saw your answers. Now I have to think.

CancelClose is the place, there is an “AppQuitting” property and also this event fires before controls are destroyed so you can still read data from them. In the close event, you can access properties, but sometimes controls are already destroyed, so you can access their values.