php如何识别回车按键,怎么给按钮加ENTER键?【已解决】

本帖最后由 qqmmcc 于 2011-9-29 12:58 编辑

在论坛里发现一个给cmd加gui界面的源码,感觉很不错,唯一的遗憾就是没有把运行按钮加ENTER键,我是AAu新手特来请教大侠们!

源码:

importwin.ui;importwin.ui.menu;importprocess/*DSG{{*/varwinform = win.form(parent=...; text="GUI_CMD";right=481;bottom=342 )

winform.add(

button={ dr=1;bottom=332;right=386;left=312;top=308;font=LOGFONT( name="宋体";h=-12 );z=4;db=1;text="运行";cls="button"};

editCon={ dr=1;dl=1;vscroll=1;right=466;left=11;dt=1;db=1;cls="richedit";bottom=299;text="";multiline=1;top=29;font=LOGFONT( name="宋体";h=-12 );z=1;hscroll=1;edge=1 };

btnCls={ dr=1;bottom=332;right=465;left=391;top=308;font=LOGFONT( name="宋体";h=-12 );z=5;db=1;text="清屏";cls="button"};

editCmd={ dr=1;dl=1;bottom=332;right=296;left=64;top=308;font=LOGFONT( name="宋体";h=-12 );z=3;db=1;text="dir c:\";edge=1;cls="edit"};

static={ dl=1;bottom=328;align="center";right=58;left=11;top=312;font=LOGFONT( name="宋体";h=-14;out=3;family=2;clip=2;quality=1 );z=2;transparent=1;db=1;color=0;text="命令:";cls="static"}

)/*}}*/onMenu =function(id){varstr = winform.popmenu.getString(id,0x0/*_MF_BYCOMMAND*/);

str = string.replace(str,"\S+$","")

winform.editCmd.text = str;

}

winform.popmenu = win.ui.popmenu(winform);//创建弹出菜单winform.popmenu.add("dir c:\ 显示磁盘目录",onMenu);

winform.popmenu.add("ver 查看系统版本号",onMenu);

winform.popmenu.add(,onMenu);varmenu = win.ui.menu(winform);//创建主菜单menu.add('DOS命令',winform.popmenu)//这个结构体在创建管道时会用到SECURITY_ATTRIBUTES =class{

INT nLength;

pointer lpSecurityDescriptor;

bool bInheritHandle;

}

winform.button.oncommand =function(id,event){

saPipe =SECURITY_ATTRIBUTES();

saPipe.bInheritHandle =true;

CreatePipe = ::Kernel32.api("CreatePipe","bool(pointer& hRead,pointer& hWrite,struct attributes,INT size)");

ok,outPipeRead,outPipeWrite = CreatePipe(,,saPipe,0)

ok,errPipeRead,errPipeWrite = CreatePipe(,,saPipe,0)//启动进程时,可以使用STARTUPINFO()结构体指定一些高级参数,//当然这个参数不是必须的,所有字段都是可选的startInfo = process.STARTUPINFO()

startInfo.flags =  0x100/*_STARTF_USESTDHANDLES*/| 0x1/*_STARTF_USESHOWWINDOW*///我们在下面设置启动进程的管道,也就是控制台程序的输入输出了//注意要在 startInfo.flags 中指定 _STARTF_USESTDHANDLES 下面的参数才起作用startInfo.stdInput = _INVALID_HANDLE_VALUE

startInfo.stdOutput =  process.dup( outPipeWrite )

startInfo.stdError =  process.dup( errPipeWrite )

startInfo.inheritHandles =true;//允许子进程继承句柄//下面我们创建进程varprcs = process("cmd.exe /c",winform.editCmd.text , startInfo);//子继承已经继承了此句柄,我们可以关掉了//否则fileCon.read()就卡在那里一直读,因为管道没关闭吗raw.closehandle(startInfo.stdOutput)

raw.closehandle(startInfo.stdError)//我们现在来创建一个文件对象,用来读取控制台程序的输出fileCon = io.open(outPipeRead)//读取一行line = fileCon.read();while(line){

winform.editCon.setsel(-1,-1);

line= string.trim(line,'\r\n')

winform.editCon.selText = line+'\n';

win.delay(1);//产生进度的效果line =  fileCon.read();

}

}

winform.btnCls.oncommand =function(id,event){

winform.editCon.text =""}

winform.show()

win.loopMessage();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值