![]() | Programming Guide | WideStudio Index Table of contents |
How to indicate a dialog on the WSEV_EXIT event procedure
There is the case to need to save data indicate a dialog whether to finish the application, when the application is finished by closing the window. In such a case it is convenient to use "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 does not exit the application. //in delayproc.java //---------------------------------------------------------- //Function for the event procedure //---------------------------------------------------------- import org.widestudio.mpfc.*; //The timer procedure which redisplay the window. public class delayproc { static WSCvtimer timer = null; static WSCbase target = null; protected static void delayproc(WSCbase object){ if (target != null){ target.setVisible((short)Mpfc.True); } } } //in exit_ep.java //---------------------------------------------------------- //Function for the event procedure //---------------------------------------------------------- import org.widestudio.mpfc.*; // EXIT event procedure // Indicates a dialog. public class exit_ep { protected static void exit_ep(WSCbase object){ if (object.getVisible() != Mpfc.False){ return; } WSCmessageDialog msg = Mpfc.WSGIappMessageDialog(); //A msg.setProperty("width",500); msg.setProperty("no",Mpfc.True); msg.setProperty("defaultPosition",Mpfc.True); msg.setProperty("labelString", "Exit and save data?\n If you do not want to save and exit,push NO..."); // Indicates the dialog. long ret = msg.popup(); //B if (delayproc.timer == null){ WSCbase parent = object.getParentWindow(); delayproc.timer = new WSCvtimer(parent,"objname"); delayproc.timer.init(); delayproc.timer.setVariantData("variable_name","delayproc.timer"); delayproc.timer.setProperty("interval",250); delayproc.timer.setProperty("cont",Mpfc.False); delayproc.timer.addProcedure("delay-popup","delayproc.delayproc",Mpfc.WSEV_ACTIVATE); } if (ret == Mpfc.WS_DIALOG_OK){ //When OK is selected.. C // saving some data ... System.exit(0); }else if (ret == Mpfc.WS_DIALOG_NO){ //When NO is selected.. D System.exit(0); }else if (ret == Mpfc.WS_DIALOG_CANCEL){ // When CANCEL is selected.. E delayproc.target = object; delayproc.timer.setProperty("running",Mpfc.True); // Start the timer to show target. } } }Get the instance of the message dialog (A),indicate it (B). Check the result of the dialog (C)(D)(E). It need to execute delayed procedure to redisplay the window, because it is required that the exit event is done before the window be redisplayed.
[The exit dialog]
Copyright(C) WideStudio Development Team, 1999-2005 | Last modified: Jan 05, 2005 |