Trapping System Menu Close Requests

A user may attempt to quit your application via the System Menu Close option or by pressing Alt F4. You may wish to intercept this action if, for example, you have unsaved changes that you want to prompt the user to handle.

You can intercept the close by providing the function app_close(), for example:

BOOLEAN app_close(int retcode)
{
  /* Your code here... */

  return TRUE;  /* To allow termination */
 return FALSE;  /* To prevent termination */
}

The parameter retcode is the code that has been passed to dp4_halt() (which in turn calls app_close()). It will have one of the following values:

0Normal termination - the program has completed
1The program has called halt() to terminate
2The user has terminated the program with <Ctrl+S> <Ctrl+C>, or has chosen Close from the System Menu under Windows, or pressed escape in sys_request()
3The program is terminating after a DP4 system error
4The program is terminating after a DP4 fail error

In the case of a Windows system menu close action, the retcode will be 2.