EndSession, QueryEndSession Events

Purpose

The EndSession event informs the application whether the session is ending. The EndSession event occurs after the system processes the results of the QueryEndSession event. QueryEndSession event occurs when the user chooses to end the session or when an application calls the ExitWindows function.

Syntax

Sub Form_ QueryEndSession(Cancel?)

Sub Form_ EndSession

Description

The WM_QUERYENDSESSION message, which is responsible for the QueryEndSession event, is sent when the user chooses to end the Windows session or when an application calls the ExitWindows function. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns halts the process. To prevent the system from ending the session, set the Cancel? variable of the QueryEndSession event to True.

After processing this message, the system sends the WM_ENDSESSION message, which leads to the EndSession event. The EndSession event sub should be as clean as possible, graphics output is not possible and file I/O should be minimized.

Cleaning up should be performed in the QueryEndSession event.

Example

OpenW 1

Do

Sleep

Until Me Is Nothing

 

Sub Win_1_QueryEndSession(Cancel?)

MsgBox "Save data?"

EndSub

 

Sub Win_1_EndSession

EndSub

Remarks

Windows doesn't send WM_CLOSE and WM_DESTROY messages when the user logs off. WM_QUERYENDSESSION is the time to do the final things.

See Also

Form, Close, Destroy

{Created by Sjouke Hamstra; Last updated: 04/10/2014 by James Gaite}