WideStudio/MWT Logo
WideStudio/MWT
Programming Guide
WideStudio/MWT Index
Table of contents


在退出 EXIT 事件处理过程中通过EXIT触发器显示对话框

关闭窗口,结束应用程序时,通常需要显示是否保存数据等询问的对话框。 此时,通过WSCwindow / WSCmainWindow类的EXIT触发器的事件过程, 可以方便的实现该目的。WSCwindow/WSCmainWindow 类在窗口变为不可见 状态时,会产生EXIT触发器。在应用程序结束前执行相应的事件过程。

首先,将作为应用程序主窗口的WSCwindow 或者WSCmainWindow 类的“exit” 属性设置为True。然后,为该窗口类的EXIT 触发器设置事件过程。

生成具有如下功能的事件过程。


  • 显示询问是否结束的对话框。

  • 当选择“OK”按钮时,执行指定的处理后结束运行。

  • 当选择“NO”按钮时,立即结束运行。

  • 当选择“CANCEL”按钮时,不做任何处理继续运行。
  • //in delayproc.java
    //----------------------------------------------------------
    //Function for the event procedure
    //----------------------------------------------------------
    import org.widestudio.mwt.*;
    // 重新显示对象的计时器处理过程
    public class delayproc {
      static WSCvtimer timer = null;
      static WSCbase target = null;
      protected static void delayproc(WSCbase object){
        if (target != null){
          target.setVisible((short)Mwt.True);
        }
      }
    }
    
    //in exit_ep.java
    //----------------------------------------------------------
    //Function for the event procedure
    //----------------------------------------------------------
    import org.widestudio.mwt.*;
    // EXIT 事件过程
    // 在程序结束时,显示对话框
    public class exit_ep {
      protected static void exit_ep(WSCbase object){
        if (object.getVisible() != Mwt.False){
          return;
        }
        WSCmessageDialog msg = Mwt.WSGIappMessageDialog();  //A
        msg.setProperty("width",500);
        msg.setProperty("no",Mwt.True);
        msg.setProperty("defaultPosition",Mwt.True);
        msg.setProperty("labelString",
          "Exit and save data?\n If you do not want to save and exit,push NO...");
    
        // 显示对话框
        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",Mwt.False);
          delayproc.timer.addProcedure("delay-popup","delayproc.delayproc",Mwt.WSEV_ACTIVATE);
        }
    
        if (ret == Mwt.WS_DIALOG_OK){           // 选择“OK”按钮的场合 C
          // saving some data ...
          System.exit(0);
        }else if (ret == Mwt.WS_DIALOG_NO){     // 选择“NO”按钮的场合 D
          System.exit(0);
        }else if (ret == Mwt.WS_DIALOG_CANCEL){ // 选择“CANCEL”按钮的场合 E
          delayproc.target = object;
          delayproc.timer.setProperty("running",Mwt.True);  // 启动计时器
        }
      }
    }
    

    A 获得信息对话框实例。B 显示信息对话框。

    C、D、E 判断对话框的返回值。

    E 继续运行重新显示时,需要使用计时器实现少许延时处理。 这是因为,在窗口系统中要求在重新显示窗口之前产生结束事件。



    [确认结束的对话框]


    Document Release 3.90 for WideStudio/MWT ver 3.90, Jul 2005


    WideStudio/MWT documents index | Table of contents

    Copyright(C) WideStudio/MWT Development Team, 1999-2005 Last modified: Jul 31, 2005