![]() | Programming Guide | WideStudio Index Table of contents |
How to indicate a dialog on the EXIT event procedure
It is necessary to save data to indicate a dialog, when you finish the application by closing the window. In such a case, it is convenient to use the WSEV_EXIT event procedure of the WSCwindow/WSCmainWindow class.
The WSCwindow/WSCmainWindow class generates the WSEV_EXIT trigger when the window is disappeared before finishing the application.
At first set True to the property "exit" of a WSCwindow/WSCmainWindow instance which is used as main window in the application, and put an event procedure to it with WSEV_EXIT trigger.
We will try to make an event procedure to have the following facility.
Indicates the dialog whether exit or continue. If [OK] is selected,execute some procedure and exit the application. If [NO] is selected,exit the application with no process. If [CANCEL] is selected, do nothing and do not exit the application. (*----------------------------------------------------------*) (*Function for the event procedure *) (*----------------------------------------------------------*) open Swig open Mpfc open Mpfclib let timer = ref C_void let target = ref C_void (* The timer procedure which redisplay the window. *) let delayproc obj = if (get_int (!target) <> 0) then ignore(!target -> setVisible ( _True)); () let _ = Callback.register "delayproc" delayproc (* EXIT event procedure *) (* Indicates a dialog. *) let exit_ep obj = (* do something...*) if get_int (obj -> getVisible()) = get_int _False then let msg = _WSGIappMessageDialog '() in begin (* A *) msg -> setProperty ( "width", 500); msg -> setProperty ( "no", _True); msg -> setProperty ( "defaultPosition", _True); msg -> setProperty ( "labelString", "Exit and save data?\n If you do not want to save and exit,push NO..."); end; (* Indicates the dialog. *) let ret = msg -> "popup"() in begin (* B *) if (timer = ref C_void) then let parent = obj -> getParentWindow () in begin timer := new_WSCvtimer ( C_list [parent; C_string "timer"]); let _ = Callback.register "timer" !timer in !timer -> init (); !timer -> setProperty ( "interval", 250 ); !timer -> setProperty ( "cont", _False ); !timer -> addProcedure ( "delay-prop", "delayproc",_WSEV_ACTIVATE ); end; if ( get_int ret = get_int _WS_DIALOG_OK ) then (* When OK is selected.. C *) (* saving some data ... *) exit 0; if ( get_int ret = get_int _WS_DIALOG_NO) then (* When NO is selected.. D *) exit 0; if ( get_int ret = get_int _WS_DIALOG_CANCEL) then begin (* When CANCEL is selected.. E *) target := obj; ignore(!timer -> setProperty ( "running", _True)); (* Start the timer to show target. *) end; end; () let _ = Callback.register "exit_ep" exit_epGet the instance of the message dialog (A),indicate it (B). Check the result of the dialog (C)(D)(E). It is necessary to execute delayed procedure to redisplay the window. Exit event is required before the window is redisplayed.
[The exit dialog]
Copyright(C) WideStudio Development Team, 1999-2005 | Last modified: Jan 05, 2005 |