App_Close event

Requires: GfaWinx.lg32

Purpose

Event sub to free global resources.

Syntax

Sub App_Close

Description

A program adds the sub App_Close to the program to release and free global resources. The event sub App_Close is always invoked even if the program terminates with a runtime error (which always happens when developing a program). The App_Close subroutine should contain the commands and functions that release global handles and memory pointers. For instance, use App_Close with FreeBmp statements to free any global bitmap handles. But App_Close is also used to release global API handles and memory allocation pointers (mFree).

Example

$Library "gfawinx"

$Library "UpdateRT"

UpdateRuntime      ' Patches GfaWin23.Ocx

OnAppClose ProcAddr(App_IsClosing)

OpenW 0, 50, 50, _X / 2, _Y / 2

Do

Sleep

Until Me Is Nothing

 

Sub App_IsClosing() ' new name, executed when app closes

MsgBox "Free resources"

CloseW 0      ' if not terminated normally

EndSub

$Group "Window Events”"

 

Sub Win_0_Click

' Genereate some error to abruptly terminate the program.

' Note that App_Close is called.

Error 3

EndSub

Remarks

By default, the compiler inserts code to execute the sub named App_Close which is called when the program is closing. Only when a program wants a different name rather than App_Close it must use OnAppClose to install a new call back event sub with a new name.

See Also

AutoFreePtr, OnAppClose.

{Created by Sjouke Hamstra; Last updated: 03/03/2022 by James Gaite}