//需要7_zip32.dll   
// 导出7_zip32.dll的 3个函数
ENVI^  Alias -opt SevenZipSetOwnerWindowEx=CALL $--ret:*  7_zip32.dll,SevenZipSetOwnerWindowEx,
ENVI^  Alias -opt SevenZip=CALL $--ret:*  7_zip32.dll,SevenZip,
ENVI^  Alias -opt SevenZipClearOwnerWindow=CALL $--ret:*  7_zip32.dll,SevenZipClearOwnerWindow,
ENVI^  Alias -opt MemoryCopy=CALL $--c --ret:*  .,MemoryCopy,

//CALL $? --ret:*  .,WndProc1_, &&WndProc1Addr //回调函数壳(STDCALL)，反射回来调用 CALL OnWndProc1 参数  
ENVI &&WM_PEBASE=0x5000    //PECMD 起始消息号 
CALC #&&WM_7ZIP=%WM_PEBASE% + 0x101
ENVI^  ForceLocal=1

WIN1
_SUB WIN1,W365H192,7Zip进度,TEAM ENVI &closeit=1|ENVI &doit=0
    ITEM ITEM3,L50T21W60H30,解压, CALL OnJieYa,
    EDIT -3D -VCENTER &SRC,L120T23W190H25,test.7z,,0x100
    LABE &LNAME,L37T71W288H18,,,
    PBAR &PBAR1,L36T91W289H16,0
    LABE -right &LSZIE,L203T116W122H20,,,
    ITEM ,L52T115W60H30,终止, ENVI &doit=0,
    ENVI @this.MSG=%&WM_7ZIP%::&&nState,&&lptag,CALL OnWM_7ZIP
    ENVI &&ok=-1
    ENVI &&closeit=0
    ENVI &&doit=1  //0为取消
    ENVI &&WID=%__WINID%
_END
_SUB  OnJieYa
    FIND $X=X%&SRC%, EXIT 
    ENVI &&WID=%__WINID%
    IFEX %&SRC%,! TEAM MESS+icon0 %&SRC% 不存在| EXIT 
    ENVI &&wcmd=x  %&SRC% -y -hide
    ENVI-tom &&acmd=&wcmd   // ANSI 编码的命令 
    ENVI-addr &&acmdadr=&acmd
    ENVI#% &&buf=*32768 
    ENVI-addr &&bufadr=&buf
    ENVI &closeit=0  //
    ENVI &ok=-1
    ENVI &doit=1  //
    ENVI^ WndProc1,&&WndProc1Addr   // WndProc1 绑定到当前 PE执行栈,以寻找 OnWndProc1 函数
    SevenZipSetOwnerWindowEx &&ret,#%__WINID% ,#%&WndProc1Addr%    //绑定到父窗口和回调函数
    SevenZip &&ret,#%__WINID%,#%&acmdadr%,#%&bufadr%,#32768    //开动7ZIP 
    SevenZipClearOwnerWindow &&ret  //父窗口和回调函数 解绑
    ENVI^ WndProc1=0  // WndProc1 解绑
    IFEX  $1=%&closeit%, EXIT 
    IFEX  $%&ok%<=-1,  MESS+icon6  解压失败@7ZIP解压演示 #OK
    IFEX  $1=%&ok%,  MESS+icon2  解压完成@7ZIP解压演示 #OK
    IFEX  $0=%&ok%,  MESS+icon0  解压取消@7ZIP解压演示 #OK
    IFEX $[ %gFS%%>0 & %gWS%<=0 ], SET ok=-2
_END

_SUB OnWM_7ZIP
    IFEX $%lptag%>0,   //结构地址非0
    {
        ENVI-make &&tag=%lptag%;8
        SET?long &tag=&&FS:0
        SET?long &tag=&&WS:4
        CALC #&FS=%&FS%
        CALC #&WS=%&WS%
        CALC &&percent= %&WS% / %&FS% * 100#0 
        SET gFS=%&FS%
        SET gWS=%&WS%
        
        // 524  + 513
        CALC #&&dstfnadr=%lptag% + 524  
        ENVI#$  &&dst=*513 0 //
        ENVI-addr &&dstadr=&dst
        MemoryCopy  ,#%&&dstadr%,#%&dstfnadr%,#513
        ENVI-tow  &&wdst=&dst
        
        ENVI @&PBAR1=%&percent% 
        ENVI @&LSZIE=%&WS%/%&FS%
        ENVI @&LNAME=%&wdst%
    }
    IFEX $2=%&nState%, TEAM  ENVI  &ok=%&doit% // MESS 完成
_END
// WndProc1 调用用户脚本函数 OnWndProc1 
//OnWndProc1 hWnd nMsg nState  lptagEXTRACTINGINFOEX
_SUB  OnWndProc1
    ENVI @@SENDMSG=%&WID%;%&WM_7ZIP%;%3;%4
    exit= %&doit% //返回1＝继续  0＝终止    
_END
   
