Home   Archive   Permalink

Trapping the X

Usually when I write a VIEW program I include a QUIT button, which usually just executes the "quit" function. But sometimes I like to do other stuff before quitting. A VIEW program can be ended also by clicking the X in the upper right (on Windows) corner. Does anyone know if I can intercept an attempted click of that X so the program doesn't quit without me gaining control for some end-of-job processing?
Thank you.

posted by:   Steven White     24-Mar-2014/13:57:09-7:00

You need to set a global event handler with INSERT-EVENT-FUNC, then you can intercept the CLOSE event.
Then, in order to quit, you need to let the event pass through the event handler, otherwise NONE to prevent quit.
See the SWITCH idiom at the bottom.
REMOVE-EVENT-FUNC is necessary in order to remove event functions created with INSERT-EVENT-FUNC.

posted by:   Henrik     24-Mar-2014/14:46:22-7:00

R E B O L []
closer: insert-event-func [
     either event/type = 'close [
         if true = request "Really close?" [remove-event-func :closer]
     ] [event]
view layout [size 600x400]

posted by:   Nick     24-Mar-2014/22:18:20-7:00

I looked at that document referenced above, and I think I have reached my own "level of incompetence." However, I did insert that little bit of code into my program and it works great. Thank you.

posted by:   Steven White     25-Mar-2014/17:49:52-7:00