|
发表于 2016-6-26 14:53:19
|
显示全部楼层
跟风的加了些,脑袋有点转不动,添加的是reghotkey,但是用了之后,本界面显示没问题,切换到别的界面按了键还是在计算器上显示,如果用消息回调mainForm.wndproc后,有时message是229 还有按键能用之后切换用鼠标按几下,再用键盘就不管用了,额~~~~~~~
- import win.ui;
- /*DSG{{*/
- mainForm = win.form(text="Aardio 计算器";right=661;bottom=376;border="thin")
- mainForm.add(
- button={cls="button";text="+";left=392;top=112;right=492;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=15};
- button10={cls="button";text="1";left=245;top=235;right=335;bottom=285;z=12};
- button11={cls="button";text="0";left=46;top=295;right=133;bottom=345;z=13};
- button12={cls="button";text="-";left=499;top=112;right=599;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=16};
- button13={cls="button";text="*";left=392;top=210;right=492;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=17};
- button14={cls="button";text="/";left=499;top=210;right=599;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=18};
- button15={cls="button";text="=";left=390;top=303;right=600;bottom=347;font=LOGFONT(name='Times New Roman';h=-48);z=1};
- button16={cls="button";text="清除";left=245;top=295;right=335;bottom=345;z=19};
- button17={cls="button";text=".";left=145;top=295;right=232;bottom=345;font=LOGFONT(h=-29);valign="top";z=20};
- button2={cls="button";text="7";left=45;top=115;right=135;bottom=165;z=4};
- button3={cls="button";text="8";left=145;top=115;right=235;bottom=165;z=5};
- button4={cls="button";text="9";left=245;top=115;right=335;bottom=165;z=6};
- button5={cls="button";text="6";left=45;top=175;right=135;bottom=225;z=7};
- button6={cls="button";text="5";left=145;top=175;right=235;bottom=225;z=8};
- button7={cls="button";text="4";left=245;top=175;right=335;bottom=225;z=9};
- button8={cls="button";text="3";left=47;top=235;right=134;bottom=285;z=10};
- button9={cls="button";text="2";left=145;top=235;right=235;bottom=285;z=11};
- edit={cls="edit";left=33;top=18;right=625;bottom=69;disabled=1;edge=1;font=LOGFONT(h=-29);z=2};
- groupbox={cls="groupbox";text="数字区";left=33;top=91;right=362;bottom=358;edge=1;z=3};
- groupbox2={cls="groupbox";text="计算区";left=377;top=91;right=625;bottom=358;edge=1;z=14}
- )
- /*}}*/
- var op=true,res=false, qian="" ,dian=false; //op 为+-*/开关 res为 等号开关 qian 为 按(+-*/)的上一步的文本内容 dian 判断小数点位置开关
- var onButtonCommand = function(id,event){
- dian=false;
- if(res){
- //判断是否按了=号 是! 覆盖文本框 否! 在后面添加
- mainForm.edit.text =owner.text;
- res=false;
- }else {
- mainForm.edit.text = mainForm.edit.text ++ owner.text;
- }
- op=true;
- qian= mainForm.edit.text;
- }
- var onButtonCommand2 = function(id){
- dian=false;
- if(res){
- //判断是否按了=号 是! 覆盖文本框 否! 在后面添加
- mainForm.edit.text =id;
- res=false;
- }else {
- mainForm.edit.text = mainForm.edit.text ++ id;
- }
- op=true;
- qian= mainForm.edit.text;
- }
- for(name,ctrl in mainForm.eachControl("button") ){
- ctrl.oncommand = onButtonCommand;
- }
- var suanshuCommand =function(id,event){
- res=false;dian=false;
- if(op){
- mainForm.edit.text = mainForm.edit.text ++ owner.text;
- op=false;
- }else {
- if(qian ==null){
- mainForm.edit.text=owner.text;
- }else {
- mainForm.edit.text=qian ++ owner.text;
- }
- }
- }
- var suanshuCommand2 =function(id){
- res=false;dian=false;
- if(op){
- mainForm.edit.text = mainForm.edit.text ++ id;
- op=false;
- }else {
- if(qian ==null){
- mainForm.edit.text=id;
- }else {
- mainForm.edit.text=qian ++ id;
- }
- }
- }
- mainForm.button12.oncommand=suanshuCommand
- mainForm.button13.oncommand=suanshuCommand
- mainForm.button14.oncommand=suanshuCommand
- mainForm.button.oncommand=suanshuCommand
- mainForm.button17.oncommand = function(id,event){
- if(res=true){
- mainForm.edit.text=""
- res=false;
- }
- if(dian=false){
- if(mainForm.edit.text == ""){
- mainForm.edit.text="0."
- dian=true
- return 0;
- }
- if(op == false){
- mainForm.edit.text=mainForm.edit.text ++ "0."
- dian=true
- return 0;
- }
- mainForm.edit.text=mainForm.edit.text ++ "."
- dian=true
- }
- }
- mainForm.button15.oncommand = function(id,event){
- try{
- mainForm.edit.text=eval(mainForm.edit.text);
- }catch(e){
- var edtext =mainForm.edit.text ;
- if(edtext=="+" || edtext=="-" || edtext=="*" || edtext=="/" ){
- mainForm.edit.text="0";
- return 0;
- }
- var v = string.match( edtext , "^(\D)" );
- if(v){
- edtext="0" ++ edtext;
- }else {
- edtext="0+" ++ edtext;
- }
- mainForm.edit.text=eval( string.match(edtext,"\d.*\d"))
- }
- qian=mainForm.edit.text;
- res=true;
- }
- mainForm.button16.oncommand = function(id,event){
- mainForm.edit.text=""
- qian=""
- }
- /**
- mainForm.wndproc = function(hwnd,message,wParam,lParam){
- select( message ) {
- case 256/*_WM_RBUTTONUP*/{
-
- select(wParam) {
- case 96 {
- onButtonCommand2("0")
- }
- case 97 {
- onButtonCommand2("1")
- }
- case 98 {
- onButtonCommand2("2")
- }
- case 99 {
- onButtonCommand2("3")
- }
- case 100 {
- onButtonCommand2("4")
- }
- case 101 {
- onButtonCommand2("5")
- }
- case 102 {
- onButtonCommand2("6")
- }
- case 103 {
- onButtonCommand2("7")
- }
- case 104 {
- onButtonCommand2("8")
- }
- case 105 {
- onButtonCommand2("9")
- }
- case 106 {
- suanshuCommand2("*")
- }
- case 107 {
- suanshuCommand2("+")
- }
- case 111 {
- suanshuCommand2("/")
- }
- case 109 {
- suanshuCommand2("-")
- }
- case 110 {
- mainForm.button17.oncommand(0,0)
- }
- }
- }
- }
- }
- **/
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("0")},0,96)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("1")},0,97)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("2")},0,98)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("3")},0,99)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("4")},0,100)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("5")},0,101)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("6")},0,102)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("7")},0,103)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("8")},0,104)
- mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("9")},0,105)
- mainForm.reghotkey( function(id,mod,vk){suanshuCommand2("*")},0,106)
- mainForm.reghotkey( function(id,mod,vk){suanshuCommand2("+")},0,107)
- mainForm.reghotkey( function(id,mod,vk){suanshuCommand2("/")},0,111)
- mainForm.reghotkey( function(id,mod,vk){suanshuCommand2("-")},0,109)
- mainForm.reghotkey( function(id,mod,vk){mainForm.button17.oncommand()},0,110)
- mainForm.show()
- return win.loopMessage();
复制代码 |
|