#code=936
ENVI^ EnviMode=1
ENVI^ ForceLocal=1
//包括定时提醒、定时运行程序、定时播放音乐、可以单次、可以多次、任务可以保存、再次启动脚本可以继续运行闹钟的定时功能
//定时播放音乐命令可以用windows媒体播放器进行，命令类似：C:\Program Files\Windows Media Player\Mplayer2.exe" /play /close 音乐文件名

ENVI^  Alias LDEBUG=@ENVI &=
ENVI^  Alias DEBUG=@ENVI &=
//ENVI  &&&Alias DEBUG=@MESS 

SET &CONFIG=%CurFile%.ini
SET  ::WM_TRAYNOTIFY=1109  //tray 通知消息
SET  ::WM_LBUTTONDOWN                  =0x0201
SET  ::WM_LBUTTONUP                    =0x0202
SET  ::WM_LBUTTONDBLCLK                =0x0203
SET  ::WM_RBUTTONDOWN                  =0x0204
SET  ::WM_RBUTTONUP                    =0x0205
SET  ::WM_RBUTTONDBLCLK                =0x0206
//Win64-pecmd32
exec*1 &&ProgramFiles=!cmd /c echo %%ProgramFiles%%
//exec*1 &&ProgramFiles(x86)=!cmd /c echo %%ProgramFiles(x86)%%  //本程序不用 

SET-env  MyName=%MyName%
SET-env  MyName0=%MyName0%
SET  ::WM_SIZE=0x0005
SET  &SIZE_MINIMIZED=1  //最小化 

SET$  &NL=0d 0a
SET$  &NLC=0a
SET$  &TAB=09

IFEX %CurFile%.LOG,   LOGS  *%CurFile%.LOG
CALL &WORK 


//加载一行
_SUB InitVarLine
    // CmdTp TimerTp times NextTime  Inter   Cmd 
    MSTR &&CmdTp,&&TimerTp,&&times,&&NextTime,&&Inter=<1*>%line%
    CALC #CmdTp=%CmdTp%
    IFEX $%CmdTp% < 1, EXIT -
    IFEX $%CmdTp% > %CMDMAX%, EXIT -
    CALC #TimerTp=%TimerTp%
    CALC #times=%times%
    CALC Inter=%Inter% * 1000  //m=>ms

    DATE *local0:%NextTime%  &&utcNextTime utc
    MSTR &&Cmd=<6->%line%

    CALC #Count=%Count% + 1
    SET &CmdTp[%Count%]=%CmdTp% 
    SET &TimerTp[%Count%]=%TimerTp% 
    SET &times[%Count%]=%times% //次数
    SET &NextTime[%Count%]=%utcNextTime% //到期
    SET &Inter[%Count%]=%Inter%  //间隔ms数
    SET &Cmd[%Count%]=%Cmd%  
    SET &Line[%Count%]=0 //表格行数 
// MESS  [%line%]
_END


// CmdTp TimerTp times NextTime  Inter   Cmd
_SUB GetCmdID
    SET &i=0
    FIND $%CMDTXT[1]%=%2, SET i=1
    FIND $%CMDTXT[2]%=%2, SET i=2
    FIND $%CMDTXT[3]%=%2, SET i=3
    FIND $%CMDTXT[4]%=%2, SET i=4
    ENVI-ret1 %1=%i%
_END

_SUB GetTimerID
    SET &i=0
    FIND $%TIMERTXT[1]%=%2, SET i=1
    FIND $%TIMERTXT[2]%=%2, SET i=2
    ENVI-ret1 %1=%i%
_END

_SUB InitVar
    SET &CMDMSG=1
    SET &CMDMUSIC=2
    SET &CMDRUN=3
    SET &CMDIN=4
    SET &CMDMAX=4
    SET &CMDTXT[1]=文本
    SET &CMDTXT[2]=音乐
    SET &CMDTXT[3]=运行程序
    SET &CMDTXT[4]=PECMD命令

    SET &TIMERINTER=1  //间隔
    SET &TIMERTO=2     //到期 
    SET &TIMERMAX=2     
    SET &TIMERTXT[1]=间隔
    SET &TIMERTXT[2]=到期 
    CALC &&S60=60000 * 10000000 //60秒 utc 
    SET &MSUTC=10000  //ms utc 
    SET &SUTC=10000000  //s utc 
    SET &MiniInter= 1000 //ms
    SET &DiffTimer%=50  //50ms,到期定时允许误差


    SET &Count=0
    SET &PLAYER=%ProgramFiles%\Windows Media Player\mplayer2.exe
    IFEX %PLAYER%,! FORX %ProgramFiles%\Windows Media Player\*player*.exe,&&f,1,SET  PLAYER=%f%
    DATE  *local:0 &&utc0 utc
    SET &Count=0
    READ %CONFIG%,*r,&&sCONFIG 
    FORX *NL &sCONFIG,&&line, CALL * InitVarLine 
    ENVI  &sCONFIG=  //Clear 
_END

_SUB UpDateTimer 
DEBUG 进入   UpDateTimer %*   
    SET &I=%1 
    SET~ &TimerTpI=TimerTp[%I%]
    IFEX $%TimerTpI%< 1, EXIT -
    IFEX $%TimerTpI%> %TIMERMAX%, EXIT -
    SET~ &InterI=Inter[%I%]
    SET~ &timesI=times[%I%]
    //间隔定时器 
    IFEX $%TimerTpI%=%TIMERINTER%,!! TEAM  CALC #&ms=%InterI%| IFEX $%timesI%>-1, SetTimer %I%  %ms%| EXIT _SUB    
    //到期定时器
    SET~ &NextTimeI=NextTime[%I%]
    DATE &&Curr utc
    CALC #&&left =  ( %NextTimeI% - %Curr% ) / %&MSUTC%  // utc => ms 
    IFEX $%left% > 0,!  //过期 
    {
        IFEX $%InterI% < %MiniInter%,  EXIT  _SUB   //无效，跳过
        CALC #&&n= ( 0 - %left%  +  %InterI% )  / %InterI%

        CALC #timesI2=%timesI% - %n%  
        IFEX $%timesI% > 0, SET  times[%I%]=%timesI2%
        IFEX $%timesI% > 0,!! IFEX $%timesI2%<1,  EXIT _SUB   //一次 //无效，跳过
        CALC #left=%InterI% * %n% + %left%
        CALC #NextTime[%I%] = %NextTimeI% + %InterI% * %n% * %&MSUTC%   //下一个定时
    }
    IFEX $%left% > 60000, SET  left=60000   //60秒
    SetTimer %I%  %left% 
_END

_SUB InitTimer
    SET &I=0
    LOOP %I% < %Count%, 
    {
        CALC #&I=%&I% + 1 
        TEAM SET &cmd=TIME &T%&I%,0,  CALL OnTimer %&I%| %cmd%  
        CALL  UpDateTimer   %I% 
    }
_END

_SUB ToTimeTxt
    IFEX $%utc0%=%~1,  ENVI %~2=0| EXIT 
    DATE *space0  *utc:%~1  &&__NextTimeI0X
    MSTR &&a1,&&a2,&&a3,&&a4,&&a5,&&a6=<1*>%__NextTimeI0X%
    ENVI %~2=%a1%-%a2%-%a3%-%a4%:%a5%:%a6%
_END

//// TAB 间隔
// CmdTp TimerTp times NextTime  Inter   Cmd 
_SUB SaveConfig
DEBUG 进入 SaveConfig  %Count%
    SET &bOld=0
    IFEX %CONFIG%, SET  bOld=1
    exec !=cmd /c type nul>%CONFIG% //兼容旧的 PECMD  ,有人还没更新PECM.EXE 
    //PUTF -dd -len=0 %CONFIG%,0,zero  //清除. //新的Pecmd.EXE支持
    //SIZE  &&sz=%CONFIG% 
    //IFEX $%sz%>0， TEAM FILE %CONFIG%| WAIT 10| SET  bOld=0  //兼容旧的 PECMD  

    WRIT %CONFIG%,1,// 命令类型: 1=文本 2=音乐 3=运行程序 4=PECMD命令 
    WRIT %CONFIG%,2,// 定时器类型: 1=间隔定时器  2=到期定时器(根据日历时间)
    WRIT %CONFIG%,3,// TAB 间隔
    WRIT %CONFIG%,4,// 命令类型  定时器类型  次数 到期时间  间隔秒数 命令或文本
    SET &I=0
    LOOP %I% < %Count%,
    {
        CALC #I=%I% + 1 
        SET~ &CmdTpI=CmdTp[%I%]
        IFEX $%CmdTpI% > %CMDMAX%, EXIT -
        IFEX $%CmdTpI% < 1, EXIT -

        SET~ &timesI=times[%I%]
        IFEX $%timesI% < 0, EXIT -
        SET~ &TimerTpI=TimerTp[%I%]
        SET~ &NextTimeI=NextTime[%I%]
        CALL * ToTimeTxt %NextTimeI%  &&NextTimeI0
        SET~ &InterI=Inter[%I%]
	CALC InterI=%InterI% / 1000 
        SET~ &CmdI=Cmd[%I%]
	FIND $0=%timesI%, SET timesI=无限
        WRIT %CONFIG%,$+0,%CmdTpI%%TAB%%TimerTpI%%TAB%%timesI%%TAB%%NextTimeI0%%TAB%%InterI%%TAB%%CmdI%
    }
    //FIND $0=%bOld%,  ENVI @@DeskTopFresh=1  //资源管理器文件列表更新 
_END

_SUB UpdateTable
//ENVI &=进入 UpdateTable %Count%
    SET  TDAT=  //1%TAB%1%TAB%2%TAB%0%TAB%2013-3-7-10:8:8.0%TAB%10%TAB%儿子的生日
    SET &I=0
    SET &LineI=1
    LOOP %I% < %Count%,
    {
        CALC #I=%I% + 1 
        SET~ &CmdTpI=CmdTp[%I%]
        IFEX $%CmdTpI% > %CMDMAX%, EXIT -
        IFEX $%CmdTpI% < 1, EXIT -
        SET Line[%I%]=%LineI% //表格行数 
        CALC #LineI=%LineI% + 1
        CALL UpdateTableI  %I%
        SET~ &TimerTpI=TimerTp[%I%]
        SET~ &CmdTpITxt=CMDTXT[%CmdTpI%]
        SET~ &TimerTpITxt=TimerTXT[%TimerTpI%]

        SET~ &timesI=times[%I%]
        SET~ &NextTimeI=NextTime[%I%]
        DATE *space0  *utc:%NextTimeI% &&NextTimeI0X
        MSTR &&a1,&&a2,&&a3,&&a4,&&a5,&&a6=<1*>%NextTimeI0X%
        SET &NextTimeI0=%a1%-%a2%-%a3%-%a4%:%a5%:%a6%
        IFEX $%utc0%=%NextTimeI%, SET  NextTimeI0=0
        SET~ &InterI=Inter[%I%]
        CALC InterI= %InterI% / 1000  //秒 
        SET~ &CmdI=Cmd[%I%]
        FIND $0=%timesI%, SET timesI=无限
        SET  TDAT=%TDAT%%NLC%%I%%TAB%%CmdTpITxt%%TAB%%TimerTpITxt%%TAB%%timesI%%TAB%%NextTimeI0%%TAB%%InterI%%TAB%%CmdI%
    }
    MSTR &TDAT=2,-1,%TDAT%
    ENVI @&TABL1.Val=-*
    ENVI @&TABL1.VAL=1*;%TDAT%
_END

//更新 %I% 行 实时更新  
_SUB UpdateTableI
//DEBUG 进入 UpdateTableI %* 
    SET~ &LineI=Line[%I%]
    IFEX $%I% > %Count%, EXIT 

    SET~ &timesI=times[%I%]
    SET~ &NextTimeI=NextTime[%I%]
    DATE *space0  *utc:%NextTimeI% &&NextTimeI0X
    MSTR &&a1,&&a2,&&a3,&&a4,&&a5,&&a6=<1*>%NextTimeI0X%
    SET &NextTimeI0=%a1%-%a2%-%a3%-%a4%:%a5%:%a6%
    IFEX $%utc0%=%NextTimeI%, SET  NextTimeI0=0
    ENVI @&TABL1.VAL=%LineI%.4;%timesI%                  //%TAB%%NextTimeI0%
    ENVI @&TABL1.VAL=%LineI%.5;%NextTimeI0%
_END


_SUB SetTimer 
    SET  &cmd= ENVI @&T%1=%2 
    %&cmd% 
_END

_SUB OnTimer 
    SET~ &TimerTpI=TimerTp[%1]
//DEBUG OnTimer   &TimerTpI=[%TimerTpI%]
    IFEX $%TimerTpI%=%TIMERINTER%, CALL OnTimerN %*! CALL OnTimerTO  %* 
_END

_SUB OnTimerTO  //到期 , 和日历时间改变有关  
DEBUG 进入 OnTimerTO   %* 
    SET &I=%~1
    SET~ &NextTimeI=NextTime[%I%]
    DATE &&Curr utc
    CALC #&&left = ( %NextTimeI% - %Curr% ) / %&MSUTC%  // utc => ms
    IFEX $%left% > %&DiffTimer%, //还没到 
    {        
        IFEX $%left% > 60000, SET  left=60000   //60秒
        SetTimer %I%  %left% 
        EXIT   
    }

    SET~ &timesI=times[%I%]
    SET~ &InterI=Inter[%I%]
//    CALC #&&nx=(  %InterI% / 2  + %InterI%  - %left%   )  / %InterI%  
    CALC #&&n= (  %InterI% / 2  + %InterI%  - %left%   )  / %InterI%  
    CALC #&&n1=1
    IFEX $%n%>-1, SET n1=%n%
    CALC &timesI=%timesI%  - %n1% 
//IFEX $%nx%=1,!  THREAD+  MESS  error nx=%nx%  left=%left% InterI=%InterI%  @-- #OK *5000 

    SET &Valid=1
    IFEX $%timesI0% > 0, SET  times[%I%]=%timesI%
    IFEX $%timesI0%>0, IFEX $%timesI%<1, SET &Valid=0  //过期了
    
    IFEX $%Valid%<1,   //过期了
    {
         SET  times[%I%]=-1 //DEL
         SetTimer %I%  0    //关闭 
    }!
    {
        CALC #&&AddTm= %n% * %InterI% 
        CALC #NextTimeI= %NextTimeI% + %AddTm%  * %MSUTC%  //下一个定时
        SET  NextTime[%I%]=%NextTimeI%
        //CALC #left = ( %NextTimeI% - %Curr% ) / %&MSUTC% 
        CALC #&left = %AddTm%   + %left%
        IFEX $%left% > 60000, SET  left=60000   //60秒
        SetTimer %I%  %left%   //下一次检查时间 
    }
    SET~ &cmdI=Cmd[%I%]
    SET~ &CmdTpI=CmdTp[%I%]
DEBUG 运行定时 OnTimerTO [%CMDIN% = %CmdTpI%]

    CALL DoTimer
 FIND $0=%bvisavle%,! CALL UpdateTableI %I% //调试  
_END

_SUB OnTimerN    //次数，和日历时间改变无关
    SET &I=%~1

    SET~ &timesI=times[%I%]
    CALC #&&timesI0=%timesI%
    CALC #timesI=%timesI% - 1 
    IFEX $%timesI% > -1,SET  times[%I%]=%timesI%
    SET~ &InterI=Inter[%I%]
    IFEX $%timesI%=0, TEAM  SET times[%I%]=-1| SetTimer %I%  0  //关闭 
    SET~ &cmdI=Cmd[%I%]
    SET~ &CmdTpI=CmdTp[%I%]
DEBUG 运行定时 OnTimerN [%CMDMSG% = %CmdTpI%]
    CALL DoTimer
_END
_SUB DoTimer
    IFEX $%bpause%=1, EXIT  //暂停
    ENVI^ ForceLocal=0
    IFEX $%&CMDMSG% = %&CmdTpI%,
    {
        SET  &cmd=THREAD+ MESS %&cmdI% @定时提醒%&I% #OK *8000
        %&cmd%
        EXIT _SUB
    }
    FIND $X=%&cmdI%X, EXIT 
    IFEX $%&CMDIN% = %&CmdTpI%,
    {
        SET  &cmd=%&cmdI%  
        %&cmd%
        EXIT _SUB 
    }
    IFEX $%&CMDRUN% = %&CmdTpI%, 
    {  
        SET  &cmd=EXEC %&cmdI%
        %&cmd%
        EXIT _SUB
    }
    IFEX %&cmdI%,! EXIT    
    IFEX $%&CMDMUSIC% = %&CmdTpI%,
    {
        SET  &cmd=EXEC "%&PLAYER%" /play /close "%&cmdI%"  
        %&cmd%
    }
_END

_SUB OnClose 
     CALL SaveConfig 
     //MESS  OnClose 
_END 

_SUB &WORK,W750H451,定时提醒,CALL OnClose,,,, -discloseb   //定时,
    SET &WID1=%&&__WinID%
    ENVI @this.Visable=0  //启动立即隐藏 
    //ENVI @this.Visable=2 
    SET &bvisavle=0  //
    SET &bpause=0  //暂停标志 
    CALL * InitVar 
    ENVI$ TAB=09
    ENVI$ NLC=0a
    ENVI$ NL=0d 0a
    SET &TITLE=#0xFF0000#0x40+40:序号%TAB%+70:命令类别%TAB%+70:定时类别%TAB%+50:次数%TAB%+120:到期时间%TAB%+60:间隔秒%TAB%250:命令/文本  
    SET &TDAT=
    CALL * InitTimer
    TABL -color:0x00F000#0x808000#0xF0E0FF &TABL1,L16T10W710H362,%TITLE%,%TDAT%,  0x940
    CALL UpdateTable
    TIME  &tmTray,1000, CALL UpdateTray 
    TIPS* 定时提醒,,,,#2   
    ENVI @this.MSG=_%&::WM_TRAYNOTIFY%::&&wp,&&lp, CALL DoMenu %wp% %lp%   
    ENVI @this.MSG=_%&::WM_SIZE%::&&wp,&&lp, CALL OnSize %wp% %lp%   
    ENVI @&TABL1.MSG=_%&::WM_LBUTTONDBLCLK%:  CALL OnTable1 
    TEAM SET &CmdTpI=| SET &TimerTpI=| SET &timesI=| SET &NextTimeI=| SET &InterI=| SET &CmdI=| SET &CmdTpITxt=| SET &TimerTpITxt=| SET &Sel=  //参数交换 
    ENVI @this.MSG=#1::&&wp,&&lp,  CALL * OnAddTimer1 %wp% 
    ENVI @&TABL1.MSG=_%&::WM_RBUTTONDBLCLK%:  CALL  OnTable1Add        
    ITEM &ITEM2,L665T380W60H30,？,CALL OnHelp,
    ITEM &BTPAUSE,L311T377W60H30,暂停,CALL OnPause,
    TIME &秒表,0,  TEAM DATE *space0 &&tm| ENVI @&LBTIME=%tm%
    LABE -vcenter &LBTIME,L40T377W203H30,,,
    CHEK &CK秒,L18T377W20H30,,CALL  OnSet秒表,
_END

_SUB OnSet秒表
    IFEX $0=%&CK秒.Check%, TEAM ENVI @&秒表=0| ENVI @&LBTIME=! ENVI @&秒表=100
_END

_SUB OnHelp
    MESS* 命令类型: 1=文本 2=音乐 3=运行程序 4=PECMD命令 \n定时器类型: 1=间隔定时器  2=到期定时器(根据日历时间) \n次数0为无限次 \n在定时项上左键双击修改，空白处则添加；右键双击添加。
_END
_SUB OnPause
    CALC #bpause= !%bpause%
    FIND $1=%bpause%, ENVI @&BTPAUSE=继续! ENVI @&BTPAUSE=暂停 
_END


_SUB  OnTable1 
    ENVI @&TABL1.Sel=?Sel
    SET  NextTimeI=
    IFEX $%Sel%<1, TEAM CALL OnTable1Add | EXIT 
    ENVI @&TABL1.Val=?%Sel%;&&SelLine
    MSTR* &&I,CmdTpITxt,TimerTpITxt,timesI,NextTimeI,InterI,CmdI=<1*>%SelLine%
    CALC  #&timesI=%timesI% 
    FIND $0=%timesI%, SET timesI=无限 
    GetCmdID   CmdTpI    %CmdTpITxt%
    GetTimerID TimerTpI  %TimerTpITxt%

    CALL @&WINModify %I%  1  
_END
_SUB  OnTable1Add    
    SET CmdTpI=1
    SET TimerTpI=1
    SET timesI=无限
    SET NextTimeI=
    SET InterI=60
    SET CmdI=
    TEAM CALC #&&I=%Count%+1| CALL @&WINModify %I%  2
_END


_SUB &WINModify,W478H361,修改定时器,
    ENVI @this=修改定时器%1
    FIND $2=%2, ENVI @this=添加定时器%1 
    LABE -vcenter &LABE2,L17T5W60H30,命令类型:,,
    SET~  &CMDTXTx=CMDTXT[%CmdTpI%]
    SET~  &TIMERTXTx=TIMERTXT[%TimerTpI%]
    LIST &ECmdTpI,L93T6W90H220,%CMDTXT[1]%|%CMDTXT[2]%|%CMDTXT[3]%|%CMDTXT[4]%,,%CMDTXTx%,
    LABE -vcenter &LABE4,L17T37W60H30,定时类型,,
    LIST &ETimerTpI,L93T41W60H220,%TIMERTXT[1]%|%TIMERTXT[2]%,CALL OnTimerTp,%TIMERTXTx%,
    LABE -vcenter &LABE6,L17T72W60H30,次数,,
    EDIT -vcenter &EtimesI,L93T73W60H30,%timesI%,,
    LABE -vcenter &LABE1,L157T72W118H30,0为无限,,
    LABE -vcenter &LABE10,L17T112W60H30,到期时间,,
    FIND $%NextTimeI%=,  DATE &&ntime1 utc! DATE *local0:"%NextTimeI%" &&ntime1 utc
    DATE *utc:%&ntime1% *space &&ntime
    MSTR &&a1,&&a2,&&a3,&&w,&&a4,&&a5,&&a6=<1*>%&ntime%
    SET &TimeTxt=%a1%-%a2%-%a3%-%a4%:%a5%:%a6%
//MESS ["%NextTimeI%"] [%&ntime1%] [%&ntime%] [%&TimeTxt%]
    SET &ENextTimeI=%&TimeTxt%
    //EDIT -vcenter &ENextTimeI,L93T111W120H30,%&TimeTxt%,,
    DTIM &DATE1,L93T113W120H24,%a1%;%a2%;%a3%,CALL  OnTime,0x20
    DTIM &TIME1,L214T113W75H24,%a4%;%a5%;%a6%,CALL  OnTime,0x40
    CALL OnTimerTp
    LABE -vcenter &LABE16,L17T147W60H30,间隔(秒),,
    EDIT -vcenter &EInterI,L93T148W60H30,%InterI%,,
    LABE -vcenter &LABE12,L16T187W90H30,命令/文本/音乐,,
    ITEM &ITEM2,L118T186W70H30,选择文件,CALL  OnBrowse,
    EDIT -vcenter &ECmdI,L17T222W431H30,%CmdI%,,
    FIND $1=%2, ITEM -vcenter &ITEM14,L84T267W60H30,修改,CALL OnModify,
    FIND $1=%2, ITEM -vcenter &ITEM15,L205T268W60H30,删除,CALL OnDel,
    FIND $2=%2, ITEM ITEM16,L322T265W60H30,添加, CALL OnAdd,
    ITEM &ITEM3,L399T7W37H30,?,CALL OnHelp,
    SET  &CheckValid=0
_END
_SUB OnTimerTp
    FIND $%ETimerTpI%=%TIMERTXT[1]%, SET &En=0! SET &En=1
    TEAM ENVI @&DATE1.Enable=%En%|  ENVI @&TIME1.Enable=%En% 
_END

_SUB OnBrowse
    BROW &&music,%ECmdI%,请选择一个文件
    FIND $ = %music%,!  ENVI @&ECmdI=%music% 
_END

_SUB OnTime  
    TEAM ENVI @&DATE1.VAL=?&&D1;&&D2;&&D3
    TEAM ENVI @&TIME1.VAL=?&&T1;&&T2;&&T3
    SET  ENextTimeI=%D1%-%D2%-%D3%-%T1%:%T2%:%T3%
_END

_SUB CheckValid
    SET CheckValid=0
    GetCmdID   CmdTpI    %ECmdTpI%
    GetTimerID TimerTpI  %ETimerTpI%
    IFEX $%CmdTpI%<1, EXIT
    IFEX $%CmdTpI%>%CMDMAX%, EXIT
    IFEX $%TimerTpI%<1, EXIT
    IFEX $%TimerTpI%>%TIMERMAX%, EXIT
    SET CheckValid=1
    SET timesI=%EtimesI%
    CALC  #&timesI=%timesI%  //整数 
    FIND $  = %ENextTimeI%, SET  ENextTimeI=0
    DATE *local0:"%ENextTimeI%" &NextTimeI  utc             
    SET  InterI=%EInterI%
    CALC InterI=%InterI% * 1000  //s=>ms
    SET  CmdI=%ECmdI%
_END

_SUB OnAdd
    CheckValid
    FIND $0=%CheckValid%, EXIT 
DEBUG ADD  1111 %I% 
    ENVI @&WORK.SENDMSG=#1;%I% 
    KILL \ 
_END

_SUB OnAddTimer1 
DEBUG 进入OnAddTimer1 %wp%
    SET  &I=%wp% 
    SET  CmdTp[%I%]=%CmdTpI%
    SET  TimerTp[%I%]=%TimerTpI%
    SET  times[%I%]=%timesI%
    SET  NextTime[%I%]=%NextTimeI%
    SET  Inter[%I%]=%InterI%
    SET  Cmd[%I%]=%CmdI%
    CALC #Count=%I%
    TEAM SET  &cmd=TIME &T%I%,0,  CALL OnTimer %I%| %cmd%   //添加定时器  
    UpDateTimer %I% 
    CALL UpdateTable 
    SaveConfig   //实时保存
_END

_SUB OnModify
DEBUG  OnModify [%ECmdTpI%] [%ETimerTpI%]     
    CheckValid
    FIND $0=%CheckValid%, EXIT 
    
    SetTimer %I%  0    //停止 
    SET  CmdTp[%I%]=%CmdTpI%
    SET  TimerTp[%I%]=%TimerTpI%
    SET  times[%I%]=%timesI%     
    SET  NextTime[%I%]=%NextTimeI%
    SET  Inter[%I%]=%InterI%
    SET  Cmd[%I%]=%CmdI%
    UpDateTimer %I% 
    CALL UpdateTable 
    SaveConfig   //实时保存
    KILL \ 
_END

_SUB OnDel
    SetTimer %I%  0  //停止
    SET  CmdTp[%I%]=0
    SET  TimerTp[%I%]=0
    SET  times[%I%]=-1
    CALL UpdateTable
    SaveConfig   //实时保存
    KILL \ 
_END



_SUB OnSize 
    IFEX $%SIZE_MINIMIZED%=%1, OnHide
_END


_SUB OnHide
    ENVI @this.Visable=0 
    SET bvisavle=0
_END

_SUB UpdateTray 
    DATE  &&CurTime 
    TIPS* 定时提醒,%&&CurTime%,,,**  //实时更新时间 , 图标不变 
_END


_SUB OnShow
    SET bvisavle=1
    CALL UpdateTable
    ENVI @this.Visable=2  
    ENVI @this.POS=::::3::1:1  
_END

_SUB OnExit
    KILL  \  
_END



_SUB DoMenu
    IFEX $%::WM_LBUTTONDOWN%=%2,!!  TEAM CALL  OnShow | EXIT
    IFEX $%::WM_LBUTTONDOWN%=%2,!  IFEX $%::WM_RBUTTONDOWN%=%2,!  EXIT BLOCK
    CALL @--popmenu       MyMenu1
_END

_SUB MyMenu1
    MENU Menu1,还原,  CALL  OnShow
    MENU -
    MENU Menu2,退出, CALl OnExit
_END

//TEAM  LOGS |EXEC $ E:\X.log
