Search documentation of wx

# View Source wxCloseEvent (wx v2.4.2)

Functions for wxCloseEvent class

This event class contains information about window and session close events.

The handler function for EVT_CLOSE is called when the user has tried to close a a frame or dialog box using the window manager (X) or system menu (Windows). It can also be invoked by the application itself programmatically, for example by calling the `wxWindow:close/2` function.

You should check whether the application is forcing the deletion of the window using `canVeto/1`. If this is false, you `must` destroy the window using `wxWindow:'Destroy'/1`.

If the return value is true, it is up to you whether you respond by destroying the window.

If you don't destroy the window, you should call `veto/2` to let the calling code know that you did not destroy the window. This allows the `wxWindow:close/2` function to return true or false depending on whether the close instruction was honoured or not.

Example of a `wxCloseEvent` handler:

The EVT_END_SESSION event is slightly different as it is sent by the system when the user session is ending (e.g. because of log out or shutdown) and so all windows are being forcefully closed. At least under MSW, after the handler for this event is executed the program is simply killed by the system. Because of this, the default handler for this event provided by wxWidgets calls all the usual cleanup code (including `wxApp::OnExit()` (not implemented in wx)) so that it could still be executed and exit()s the process itself, without waiting for being killed. If this behaviour is for some reason undesirable, make sure that you define a handler for this event in your wxApp-derived class and do not call `event.Skip()` in it (but be aware that the system will still kill your application).

See: `wxWindow:close/2`, Overview windowdeletion

This class is derived (and can use functions) from: `wxEvent`

wxWidgets docs: wxCloseEvent

## Events

Use `wxEvtHandler:connect/3` with `wxCloseEventType` to subscribe to events of this type.

# Summary

## Types

wxClose()
wxCloseEvent()
wxCloseEventType()

## Functions

canVeto(This)

Returns true if you can veto a system shutdown or a window close event.

getLoggingOff(This)

Returns true if the user is just logging off or false if the system is shutting down.

setCanVeto(This, CanVeto)

Sets the 'can veto' flag.

setLoggingOff(This, LoggingOff)

Sets the 'logging off' flag.

veto(This)
veto/2

Call this from your event handler to veto a system shutdown or to signal to the calling application that a window close did not happen.

# Types

Link to this type

# wxClose()

View Source

    -type wxClose() :: #wxClose{type :: wxCloseEvent:wxCloseEventType()}.

Link to this type

# wxCloseEvent()

View Source

    -type wxCloseEvent() :: wx:wx_object().

Link to this type

# wxCloseEventType()

View Source

    -type wxCloseEventType() :: close_window | end_session | query_end_session.

# Functions

Link to this function

# canVeto(This)

View Source

    -spec canVeto(This) -> boolean() when This :: wxCloseEvent().

Returns true if you can veto a system shutdown or a window close event.

Vetoing a window close event is not possible if the calling code wishes to force the application to exit, and so this function must be called to check this.

Link to this function

# getLoggingOff(This)

View Source

    -spec getLoggingOff(This) -> boolean() when This :: wxCloseEvent().

Returns true if the user is just logging off or false if the system is shutting down.

This method can only be called for end session and query end session events, it doesn't make sense for close window event.

Link to this function

# setCanVeto(This, CanVeto)

View Source

    -spec setCanVeto(This, CanVeto) -> ok when This :: wxCloseEvent(), CanVeto :: boolean().

Sets the 'can veto' flag.

Link to this function

# setLoggingOff(This, LoggingOff)

View Source

    -spec setLoggingOff(This, LoggingOff) -> ok when This :: wxCloseEvent(), LoggingOff :: boolean().

Sets the 'logging off' flag.

Link to this function

# veto(This)

View Source

    -spec veto(This) -> ok when This :: wxCloseEvent().

Link to this function

# veto/2

View Source

    -spec veto(This, [Option]) -> ok when This :: wxCloseEvent(), Option :: {veto, boolean()}.

Call this from your event handler to veto a system shutdown or to signal to the calling application that a window close did not happen.

You can only veto a shutdown if `canVeto/1` returns true.