规范代码重新写了一遍, 问题自然就没有了.
代码不规范,思路也就乱,问题也就多,找起来也很痛苦,
import win.ui;
import process;
/*DSG{{*/
var winform = ..win.form( bottom=400;parent=...;right=479;text="aardio Form" )
winform.add(
btnListProcess={ bottom=40;text="显示所有进程";left=296;top=8;z=4;right=376;cls="button" };
listview={ bgcolor=16777215;bottom=392;right=472;left=8;top=48;z=6;edge=1;cls="listview" };
button={ bottom=40;text="KILL";left=208;top=8;z=3;right=288;cls="button" };
static={ bottom=72;right=160;left=8;top=16;transparent=1;notify=1;text="请输入进程PID";z=1;cls="static" };
editProcId={ bottom=32;right=200;left=104;top=8;z=2;edge=1;cls="edit" };
btnRefresh={ bottom=40;text="刷新";left=384;top=8;z=5;right=464;cls="button" }
)
/*}}*/
//列表视图添加列
tlv={ { "进程名称";150};{ "进程PID";150};{ "进程使用内存";-1} }
for ( i,column in tlv ){
winform.listview.insertColumn(column[1],column[2] );
}
//杀除进程
winform.button.oncommand = function(id,event){
var prcId = tonumber(winform.editProcId.text)
process(prcId).terminate()
}
//列表视图响应鼠标点击
winform.listview.onnotify = function(id,code,ptr){
select(code) {
case 0xFFFFFF9B/*_LVN_ITEMCHANGED*/ {
var nm = winform.listview.getNotifyMessage(code,ptr)
if(winform.listview.selIndex){
winform.editProcId.text = winform.listview.getItemText(nm.iItem,2)
}
}
case 0xFFFFFFFB/*_NM_RCLICK*/ {
var x,y = mouse.getPos()
//弹出菜单
}
}
}
//获取进程内存
GetProcessMemoryInfo = ::Psapi.api("GetProcessMemoryInfo","int(pointer hProcess,struct& ppsmemCounters,int cb)")
PROCESS_MEMORY_COUNTERS= class{
int cb;
int PageFaultCount;
int PeakWorkingSetSize; //物理内存的最大值
int WorkingSetSize; //物理内存的大小
int QuotaPeakPagedPoolUsage;
int QuotaPagedPoolUsage;
int QuotaPeakNonPagedPoolUsage;
int QuotaNonPagedPoolUsage;
int PagefileUsage; //虚拟内存大小
int PeakPagefileUsage; //虚拟内存的最大值
}
memory_counters =PROCESS_MEMORY_COUNTERS()
import fsys;
listProcess = function(){
winform.listview.clear();
win.delay(500);
for processEntry in process.each( ".*.exe" ) {
var prc=process(processEntry.th32ProcessID)
if(!prc) continue;
GetProcessMemoryInfo(prc.handle,memory_counters,raw.sizeof(memory_counters))
procName=processEntry.szExeFile //进程名称
procId=processEntry.th32ProcessID //进程PID
procMem= fsys.formatSize(memory_counters.WorkingSetSize)
var row = winform.listview.addItem(procName ) //插入的行数
winform.listview.setItemText(tostring(procId),row,2)
winform.listview.setItemText(procMem,row,3)
}
}
listProcess();
winform.btnRefresh.oncommand = function(id,event){
listProcess();
}
winform. btnListProcess.oncommand = function(id,event){
listProcess();
}
winform.text="进程管理器"
winform.show()
win.loopMessage();
return winform; |