IFEX %&CurDir%\X.LOG, LOGS *%&CurDir%\X.%&__PID%.LOG 
ENVI^   ForceLocal=1
NAME  &&PROG=%CurFile%
SET-def BinPROG="%CurDir%\%PROG%.exe"
IFEX %PROG%.ntr, SET BinPROG="%CurDir%\%PROG%.ntr"
IFEX %PROG%.exe, SET BinPROG="%CurDir%\%PROG%.exe"

PATH @%__OldDir%
MSTR CurFile=<~1>%CurFile%


////------------注册------------
SET-def  MENU=%PROG%
FIND $X=X%*, TEAM CALL @WINREG| EXIT FILE
_SUB WINREG,W289H237,注册%PROG%,
    LABE LABE2,L23T77W120H30,显示右键菜单：,,
    EDIT -vcenter StrMenu,L22T111W235H30,,,
    ITEM ITEM4,L103T163W60H30,注册,CALL OnREG,
    TIME -t:1 T1,10,CALL INIT1
    LABE -vcenter LABE1,L20T27W30H30,类型:,,
    EDIT -vcenter FTYPE,L50T26W117H30,*,,
    LABE -vcenter LABE3,L169T26W100H30,*为全部;空格分隔,,
_END
_SUB INIT1
    IFEX %CurFile%.INI, LOAD "%CurFile%.INI" 
    ENVI @StrMenu=%MENU%
_END

_SUB OnREG
    LOCK #pecmd
    FIND $%FTYPE%=, ENVI @FTYPE=*
    FORX * %FTYPE%,&&FTYPE1,
    {
        FIND $%PROG%=%StrMenu%,!  REGI $HKEY_CLASSES_ROOT\%FTYPE1%\shell\%PROG%\=%StrMenu%
        REGI $HKEY_CLASSES_ROOT\%FTYPE1%\shell\%PROG%\Command\=pecmd load "%CurFile%" "%%L"
    }
    regi $HKCU\Software\PECMD\%&PROG%\HWND=  //初始化
_END



////------------正常运行------------

SET-def  hwnd0=0 
SET-def FILES=
CALL @WIN1 %*
IFEX $%hwnd0%=0,!  UnREGWND
_SUB WIN1,W289H249,,
    ENVI @this.visable=0
    ENVI @this.MSG=#1::wp,lp, CALL OnSET  
    CALL  REGWND  %&__WinID%
    CALL  ADDFile %* 
    IFEX $%hwnd0%=0, KILL \
    SET-def bDo=0  //空闲计数 
    TIME Timer1,100, CALL OnEXEC  
_END

_SUB OnEXEC
    CALC #bDo=%bDo% + 1
    IFEX $%bDo%<3, EXIT 
    ENVI @Timer1=0 //停止 
    KILL \ 
    ENVI @this.Visable=0
    FIND $X=X%FILES%, EXIT 
    CALL UnREGWND
    EXEC =%BinPROG% %FILES%
_END

_SUB REGWND
    LOCK #pecmd
    regi $HKCU\Software\PECMD\%&PROG%\HWND,&&HWND
    CALC #HWND=%HWND%
    IFEX $%HWND%=0,!
    {   ENVI @@IsWindow=?%&HWND%:&&v1
        FIND $1=%&&v1%,! SET  HWND=0
    }
    IFEX $%HWND%=0,  TEAM regi $HKCU\Software\PECMD\%PROG%\HWND=%1| SET hwnd0=%1 //注册
_END

_SUB UnREGWND
    IFEX $%hwnd0%=0, EXIT _SUB
    { LOCK #pecmd
        regi $HKCU\Software\PECMD\%&PROG%\HWND=  //反注册
    SET hwnd0=0
    }
    //IFEX %&CurDir%\X.LOG, EXEC $%&CurDir%\X.LOG
_END


_SUB ADDFile 
    LOCK #pecmd
    regi $HKCU\Software\PECMD\%&PROG%\HWND,&&HWND
    CALC #&HWND=%&HWND%
    IFEX $%&HWND%=0,   EXIT
    regi $HKCU\Software\PECMD\%&PROG%\NAME=%*
    ENVI @@SENDMSG=%&HWND%:#1
_END


_SUB OnSET  
    regi $HKCU\Software\PECMD\%&PROG%\NAME,&&NM
    FIND $X=X%&NM%, EXIT
    SET FILES=%FILES% %&NM%
    SET bDo=0  //有新东西 
_END
