Trapping the X

Started by Steven White on 24-Mar-2014/13:57:09-7:00
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.
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. http://www.rebol.com/docs/view-face-events.html See the SWITCH idiom at the bottom. REMOVE-EVENT-FUNC is necessary in order to remove event functions created with INSERT-EVENT-FUNC.
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]
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.

Reply