#code=936T950
//2015-06-23,by:JexChan,QQ:527104427
ENVI^ EnviMode=1
ENVI^ ForceLocal=1
ENVI &&WM_SIZE=0x0005
ENVI &&SIZE_MAXHIDE=4
ENVI &&SIZE_MAXSHOW=3
ENVI &&SIZE_MAXIMIZED=2
ENVI &&SIZE_MINIMIZED=1
ENVI &&SIZE_RESTORED=0
ENVI &&WM_RBUTTONDOWN=0x0204
ENVI &&WM_KEYDOWN=0x0100
ENVI &&WM_COMMAND=0x0111
ENVI &&EN_CHANGE=0x0300
SET$ &&TAB=09
SET$ &&NL=0d 0a
TEAM ENVI &Wide2=450| ENVI &High2=475| ENVI &Font_Size=9| ENVI &Font_Size1=| REGI #HKCU\Control Panel\Desktop\WindowMetrics\AppliedDPI,&Font_Size1| FIND $%&Font_Size1%=, ENVI &Font_Size1=96|
ENVI &Font_Cmd=IFEX %windir%\fonts\simsun*, ENVI @this.Font=%&Font_Size%:simsun! ENVI @this.Font=%&Font_Size%
SET &DPI=%&Font_Size1%/96
CALL @WIN1

_SUB WIN1,W%&Wide2%H%&High2%,进程管理器,,,,, -maxb -size -scalef -scale
	ENVI @this.POS=?::&Z1:&Z2
	IFEX $[ %&Z1%=%&Wide2% & %&Z2%=%&High2% ], ENVI &DPI=1
	%&Font_Cmd%
	ITEM -def &&I1,L366T390W64H22,结束进程,DoKill,
	ITEM &&I2,L212T390W85H22,复制到剪贴板,Copy_Clipboard,
	CHEK &&C1,L299T391W43H20,全部,,
	CHEK &&C2,L14T391W111H20,自动刷新(毫秒)：, CALL Fresh,1
	EDIT -3d -vcenter &&E1,L127T389W60H23,1000,,0x400
	LABE -left &&LB1,L30T425W100H21,进程数：,
	LABE -left &&LB2,L145T425W140H21,CPU使用率：,*,
	LABE -left &&LB3,L300T425W160H21,物理内存：,*,
	LABE -3d &&LB4,L-5T419W455H1,
	TEAM CALC #&de6=50*%&DPI%| CALC #&de7=65*%&DPI%| CALC #&de8=125*%&DPI%| CALC #&de9=600*%&DPI%| CALC #&dea=570*%&DPI%|
	//ENVI &&Title=+%&de6%:进程号%&TAB%+%&de6%:父进程%&TAB%=%&de7%:内存(KB) %&TAB%*%&de8%:CPU使用时间(100ns) %&TAB%*%&de8%:总时间%&TAB%*%&de9%:  文件路径%&TAB%*%&dea%:  参数
	ENVI &&Title=+%&de6%:进程号%&TAB%+%&de6%:父进程%&TAB%=%&de7%:内存(KB) %&TAB%*0:CPU使用时间(100ns) %&TAB%*0:总时间%&TAB%*%&de9%:  文件路径%&TAB%*%&dea%:  参数
	TABL &&TL1,L14T17W415H363,%&Title%,,0x10040
	ENVI @&&TL1.POS=?::&Z3:&Z4
	ENVI @&&I1.POS=?&Z5:&Z6
	ENVI @&&C1.POS=?&Z7:&Z8
	ENVI @&&I2.POS=?&Z9:&ZA
	ENVI @&&C2.POS=?:&ZB
	ENVI @&&E1.POS=?:&ZC
	ENVI @&&LB1.POS=?:&ZD
	ENVI @&&LB2.POS=?:&ZE
	ENVI @&&LB3.POS=?:&ZF
	ENVI @&&LB4.POS=?:&ZG:&ZH
	ENVI &CPUS=1
	FIND --pid &TMS,
	MSTR &II1=<1>%&TMS%
	MSTR &TT1=<2>%&TMS%
	MSTR &CPUS=<3>%&TMS%
	ENVI &Last=-100
	TIME &&TM1,0, TEAM Fresh| Status|
	TEAM Fresh| Status|
	FORX * &&I1 &&I2 ,&v, ENVI @%&v%.Cursor=32649
	ENVI @&&TL1.MSG=_%&WM_RBUTTONDOWN%: CALL @--popmenu MyMenu1
	ENVI @&&TL1.MSG=_%&WM_KEYDOWN%::&&wParm,&&lParm,CALL OnKey %&wParm% %&lParm%
	ENVI @WIN1.MSG=%&WM_SIZE%::&&wParm,&&lParm,CALL OnSize_WIN1 %&wParm% %&lParm%
	ENVI @&&E1.ID=?;&&E1_ID
	CALC -base=16 #&&E1_CHANGE=%&EN_CHANGE% * 0x10000 + %&E1_ID%
	ENVI @this.MSG=_%&WM_COMMAND%::&&wp,&&lp,CALL E2
	ENVI @&&LB3.MSG=0x02A1: Mouse_In 物理内存概况,可用内存：%&MemU% M%&NL%总内存：%&MemA% M
	ENVI @&&LB2.MSG=0x02A1: Mouse_In CPU,线程数：%&CPUS%
	Mouse_Out &&LB3 &&LB2
_END

_SUB Mouse_In
	TEAM ENVI @@Cur=?&vs;&vr| TIPS* %*,1000000000,1,@AL%&vs%T%&vr%
_END

_SUB Mouse_Out
	FORX * %* ,&vt,ENVI @%&vt%.MSG=0x02A3: TIPS *
_END

_SUB Status *
	IFEX MEMU=?,&MemU
	IFEX MEMA=?,&MemA
	CALC &vu= 100 - 100 * %MemU% / %MemA% ##1
	ENVI @&&LB3=物理内存：%&vu%%
	FIND --pid &TMS,
	MSTR &II2=<1>%&TMS%
	MSTR &TT2=<2>%&TMS%
	CALC #&II21=%&II2% - %&II1%
	CALC #&TT21=%&TT2% - %&TT1%
	CALC &P= 100 - 100 * %&II21% / %&TT21% / %&CPUS% ##1
	FIND $%&P%=-0.0, ENVI &P=0
	IFEX $%&P%<0, EXIT
	IFEX $%&Last%=%&P%, EXIT 
	SET &Last=%&P%
	ENVI @&&LB2=CPU使用率：%&P%%%
	ENVI &II1=%&II2%
	ENVI &TT1=%&TT2%
_END

_SUB File_Dir
	ENVI @&&TL1.Sel=?&&Sel
	ENVI @&&TL1.Val=?%&Sel%.6;&vz
	FIND $'%&vz%'='',EXIT
	//EXPLORER.EXE [/n][/e][,/root,<object>][[,/select],<sub object>]
	EXEC EXPLORER.EXE /n,/select,%&vz%
	//下面是旧的方法，先打开目录，再发送文件名
	//MSTR &v1=1,12,%&v%
	//FIND $'%&v1%'='\SystemRoot\', TEAM MSTR &v=12-,0,%&v%| ENVI &v=%SystemRoot%%&v%|
	//FDIR --short --full &v1=%&v%
	//FNAM -ext &v3=%&v%
	//EXEC --wait EXPLORER.EXE "%&v1%"
	//TEAM ENVI &v2=| ENVI &i=1|
	//LOOP #1=1,
	//{*
	//	MSTR &v1=%&i%,1,%&v3%
	//	MSTR &v4=%&i%-,0,%&v3%
	//	MSTR &v4=<~1>%&v4%
	//	FIND $[ '%&v1%'='' & '%&v4%'='' ], EXIT LOOP
	//	ENVI &v2=%&v2%;%&v1%
	//	CALC &i=%&i%+1
	//}
	//MSTR &v2=2-,0,%&v2%
	//WAIT 500
	//MESS %&v2%
	//SEND %&v2%
_END

_SUB E2
	IFEX $[ %&E1_CHANGE%=%&wp% & %&C2.Check%=1 ], CALL Start_TM1
_END

_SUB Copy_Clipboard
	IFEX $%&C1.Check%=1, ENVI &v=1! ENVI &v=
	CALL Clipboard %&v%
_END

_SUB Clipboard
	FIND $'%1'='',
	{*
		ENVI @&&TL1.Sel=?&&Sel
		IFEX $1>%&Sel%,EXIT _SUB
		ENVI @&&TL1.Val=?%&Sel%;&vy
	}!   
	{*
		FIND --pid*@  &vy,
	}
	ENVI^ Clipboard=%&vy%
	MESS+icon \n\n     成功复制！ @提示#OK *5000
_END

_SUB DoKill
	ENVI @&&TL1.Sel=?&&Sel
	IFEX $1>%&Sel%,EXIT
	ENVI @&&TL1.Val=?%&Sel%.1;&vx
	MESS \n\n确定结束进程 %&vx% 吗？ @提示#YN $N *5000
	FIND $YES<>%&YESNO%, EXIT
	KILL *%&vx%
_END

_SUB OnKey
	IFEX $%&wParm%=0x2E, CALL DoKill
_END

_SUB MyMenu1
	ENVI @&&TL1.Sel=?&&Sel
	IFEX $1>%&Sel%,EXIT
	MENU Menu1,打开文件位置, File_Dir
	MENU -
	MENU Menu2,复制到剪贴板, Clipboard
	MENU -
	MENU Menu3,结束进程, DoKill
_END

_SUB Fresh
	IFEX $%&C2.Check%=1, CALL Start_TM1 ! CALL Stop_TM1
_END

_SUB Stop_TM1
	ENVI @&&TM1=0
_END

_SUB Start_TM1
	CALL Process
	CALC #&&vw=%&E1%
	ENVI @&&TM1=%&vw%
_END

_SUB Process
	FIND --pid*@  &vv,
	ENVI @&&TL1.Val=1*#;%&vv%
	ENVI @&&TL1.Val=?*;&vv
	ENVI @&&LB1=进程数：%&vv% 
_END

_SUB OnSize_WIN1
	TEAM ENVI &sz=0| ENVI &w=0| ENVI &h=0| CALC #&tmp1=415*%&DPI%| CALC #&tmp2=363*%&DPI%|
	IFEX $%1 = %&SIZE_MAXIMIZED%, ENVI &sz=1
	IFEX $%1 = %&SIZE_MAXSHOW%, ENVI &sz=1
	IFEX $%1 = %&SIZE_RESTORED%, ENVI &sz=1
	IFEX $1=%&sz%,
	{
		ENVI &LP=%2
		CALC #&w= %&LP% & 0xFFFF   //LOW
		CALC #&h= %&LP% / 0x10000  //HIGH
		CALC &w= %&w% - 29*%&DPI%#0
		CALC &h= %&h% - 80*%&DPI%#0
		IFEX $[ %&w%<%&tmp1% | %&h%<%&tmp2% ], 
		{
			ENVI @WIN1.POS=::%&Z1%:%&Z2%
			ENVI @&&TL1.POS=::%&Z3%:%&Z4%
			ENVI @&&I1.POS=%&Z5%:%&Z6%
			ENVI @&&C1.POS=%&Z7%:%&Z8%
			ENVI @&&I2.POS=%&Z9%:%&ZA%
			ENVI @&&C2.POS=:%&ZB%
			ENVI @&&E1.POS=:%&ZC%
			ENVI @&&LB1.POS=:%&ZD%
			ENVI @&&LB2.POS=:%&ZE%
			ENVI @&&LB3.POS=:%&ZF%
			ENVI @&&LB4.POS=:%&ZG%:%&ZH%
			EXIT _SUB
		}
		CALC #&w1= %&w% + 40*%&DPI%
		CALC #&L= %&w% + 14*%&DPI%
		CALC #&T= %&h% + 27*%&DPI%
		CALC #&T1= %&T% + 1*%&DPI%
		CALC #&T2= %&T% - 1*%&DPI%
		CALC #&T4= %&T% + 29*%&DPI%
		CALC #&T5= %&T4% + 6*%&DPI%
		CALC #&L1= %&L% - 65*%&DPI%
		CALC #&L2= %&L% - 130*%&DPI%
		CALC #&L3= %&L% - 225*%&DPI%
		ENVI @&&TL1.POS=::%&w%:%&h%
		ENVI @&&I1.POS=%&L1%:%&T%
		ENVI @&&C1.POS=%&L2%:%&T1%
		ENVI @&&I2.POS=%&L3%:%&T%
		ENVI @&&C2.POS=:%&T1%
		ENVI @&&E1.POS=:%&T2%
		ENVI @&&LB4.POS=:%&T4%:%&w1%
		ENVI @&&LB1.POS=:%&T5%
		ENVI @&&LB2.POS=:%&T5%
		ENVI @&&LB3.POS=:%&T5%
		ENVI @this.InvalidateRect=
	}
_END
