aardio 官方社区

用户名  找回密码
 注册会员

QQ登录

只需一步,快速开始

帖子
查看: 26946|回复: 4

aardio 计算器 源码分享

[复制链接]

4

主题

5

回帖

72

积分

培训班

积分
72
发表于 2016-6-23 23:45:28 | 显示全部楼层 |阅读模式
源码如下

  1. import win.ui;
  2. /*DSG{{*/
  3. mainForm = win.form(text="Aardio 计算器";right=661;bottom=376)
  4. mainForm.add(
  5. button={cls="button";text="+";left=392;top=112;right=492;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=14};
  6. button10={cls="button";text="1";left=245;top=235;right=335;bottom=285;z=11};
  7. button11={cls="button";text="0";left=46;top=295;right=235;bottom=345;z=12};
  8. button12={cls="button";text="-";left=499;top=112;right=599;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=15};
  9. button13={cls="button";text="*";left=392;top=210;right=492;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=16};
  10. button14={cls="button";text="/";left=499;top=210;right=599;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=17};
  11. button15={cls="button";text="=";left=390;top=303;right=600;bottom=347;font=LOGFONT(name='Times New Roman';h=-48);z=18};
  12. button16={cls="button";text="清除";left=245;top=295;right=335;bottom=345;z=19};
  13. button2={cls="button";text="7";left=45;top=115;right=135;bottom=165;z=3};
  14. button3={cls="button";text="8";left=145;top=115;right=235;bottom=165;z=4};
  15. button4={cls="button";text="9";left=245;top=115;right=335;bottom=165;z=5};
  16. button5={cls="button";text="6";left=45;top=175;right=135;bottom=225;z=6};
  17. button6={cls="button";text="5";left=145;top=175;right=235;bottom=225;z=7};
  18. button7={cls="button";text="4";left=245;top=175;right=335;bottom=225;z=8};
  19. button8={cls="button";text="3";left=47;top=235;right=134;bottom=285;z=9};
  20. button9={cls="button";text="2";left=145;top=235;right=235;bottom=285;z=10};
  21. edit={cls="edit";left=33;top=18;right=625;bottom=69;edge=1;font=LOGFONT(h=-29);multiline=1;z=1};
  22. groupbox={cls="groupbox";text="数字区";left=33;top=91;right=362;bottom=358;edge=1;z=2};
  23. groupbox2={cls="groupbox";text="计算区";left=377;top=91;right=625;bottom=358;edge=1;z=13}
  24. )
  25. /*}}*/

  26. var onButtonCommand = function(id,event){
  27.        
  28.     mainForm.edit.text = mainForm.edit.text ++ owner.text;
  29. }

  30. for(name,ctrl in mainForm.eachControl("button") ){
  31.     ctrl.oncommand = onButtonCommand;
  32.    
  33. }
  34. mainForm.button15.oncommand = function(id,event){
  35.                 mainForm.edit.text=eval(mainForm.edit.text);
  36. }
  37. mainForm.button16.oncommand = function(id,event){
  38.         mainForm.edit.text=""
  39. }

  40. mainForm.show()
  41. return win.loopMessage();

复制代码


生成效果
QQ截图20160623234431.png
已知Bug:
如果不按数字,只按运算符,再点击等号。会报错。需要加个算式的判定。

4

主题

5

回帖

72

积分

培训班

积分
72
 楼主| 发表于 2016-6-24 13:04:54 | 显示全部楼层
本帖最后由 xiqingongzi 于 2016-6-25 23:28 编辑

更新功能:
实现按钮输入,自动获取焦点。集成按键控制。按下回车键自动输入
  1. import win.ui;
  2. /*DSG{{*/
  3. mainForm = win.form(text="Aardio 计算器";right=661;bottom=376)
  4. mainForm.add(
  5. button={cls="button";text="+";left=392;top=112;right=492;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=14};
  6. button10={cls="button";text="1";left=245;top=235;right=335;bottom=285;z=11};
  7. button11={cls="button";text="0";left=46;top=295;right=235;bottom=345;z=12};
  8. button12={cls="button";text="-";left=499;top=112;right=599;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=15};
  9. button13={cls="button";text="*";left=392;top=210;right=492;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=16};
  10. button14={cls="button";text="/";left=499;top=210;right=599;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=17};
  11. button15={cls="button";text="=";left=390;top=303;right=600;bottom=347;font=LOGFONT(name='Times New Roman';h=-48);z=18};
  12. button16={cls="button";text="清除";left=245;top=295;right=335;bottom=345;z=19};
  13. button2={cls="button";text="7";left=45;top=115;right=135;bottom=165;z=3};
  14. button3={cls="button";text="8";left=145;top=115;right=235;bottom=165;z=4};
  15. button4={cls="button";text="9";left=245;top=115;right=335;bottom=165;z=5};
  16. button5={cls="button";text="6";left=45;top=175;right=135;bottom=225;z=6};
  17. button6={cls="button";text="5";left=145;top=175;right=235;bottom=225;z=7};
  18. button7={cls="button";text="4";left=245;top=175;right=335;bottom=225;z=8};
  19. button8={cls="button";text="3";left=47;top=235;right=134;bottom=285;z=9};
  20. button9={cls="button";text="2";left=145;top=235;right=235;bottom=285;z=10};
  21. edit={cls="edit";left=33;top=18;right=625;bottom=66;edge=1;font=LOGFONT(h=-29);multiline=1;tabstop=1;z=1};
  22. groupbox={cls="groupbox";text="数字区";left=33;top=91;right=362;bottom=358;edge=1;z=2};
  23. groupbox2={cls="groupbox";text="计算区";left=377;top=91;right=625;bottom=358;edge=1;z=13}
  24. )
  25. /*}}*/

  26. var onButtonCommand = function(id,event){
  27.        
  28.     mainForm.edit.text = mainForm.edit.text ++ owner.text;
  29. }
  30. for(name,ctrl in mainForm.eachControl("button") ){
  31.     ctrl.oncommand = onButtonCommand;
  32.    
  33. }
  34. mainForm.button15.oncommand = function(id,event){
  35.                 mainForm.edit.text=eval(mainForm.edit.text);
  36. }
  37. mainForm.button16.oncommand = function(id,event){
  38.         mainForm.edit.text=""
  39. }

  40. import key.hook;
  41. var hook=key.hook();
  42. hook.proc = function(msg,vkcode,scancode,injected,flags,timeStamp,extraInfo){
  43.         if( injected ) return;         
  44.    
  45.     select(msg) {
  46.             case 0x100/*_WM_KEYDOWN*/ ,0x104/*_WM_SYSKEYDOWN*/{
  47.                     mainForm.edit.setFocus();
  48.             }
  49.             case 0x101/*_WM_KEYUP*/,0x105/*_WM_SYSKEYUP*/{
  50.                  if(vkcode == 13){
  51.                                mainForm.edit.text=eval(mainForm.edit.text);
  52.                                mainForm.msgbox("您的计算结果是"++mainForm.edit.text)
  53.                               
  54.                }
  55.             }  
  56.     }   

  57. }
  58. mainForm.show()
  59. return win.loopMessage();
复制代码


---------------------------------------------------------------------------------
更新:调整了热键监听。加入错误处理。

  1. import win.ui;
  2. /*DSG{{*/
  3. mainForm = win.form(text="西秦的练手计算器";right=661;bottom=465)
  4. mainForm.add(
  5. button={cls="button";text="+";left=392;top=112;right=492;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=14};
  6. button10={cls="button";text="1";left=245;top=235;right=335;bottom=285;z=11};
  7. button11={cls="button";text="0";left=46;top=295;right=235;bottom=345;z=12};
  8. button12={cls="button";text="-";left=499;top=112;right=599;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=15};
  9. button13={cls="button";text="*";left=392;top=210;right=492;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=16};
  10. button14={cls="button";text="/";left=499;top=210;right=599;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=17};
  11. button15={cls="button";text="=";left=392;top=303;right=600;bottom=347;font=LOGFONT(name='Times New Roman';h=-48);z=18};
  12. button16={cls="button";text="清除";left=245;top=295;right=335;bottom=345;z=19};
  13. button2={cls="button";text="7";left=45;top=115;right=135;bottom=165;z=3};
  14. button3={cls="button";text="8";left=145;top=115;right=235;bottom=165;z=4};
  15. button4={cls="button";text="9";left=245;top=115;right=335;bottom=165;z=5};
  16. button5={cls="button";text="6";left=45;top=175;right=135;bottom=225;z=6};
  17. button6={cls="button";text="5";left=145;top=175;right=235;bottom=225;z=7};
  18. button7={cls="button";text="4";left=245;top=175;right=335;bottom=225;z=8};
  19. button8={cls="button";text="3";left=47;top=235;right=134;bottom=285;z=9};
  20. button9={cls="button";text="2";left=145;top=235;right=235;bottom=285;z=10};
  21. edit={cls="edit";left=33;top=18;right=625;bottom=66;edge=1;font=LOGFONT(h=-29);multiline=1;tabstop=1;z=1};
  22. groupbox={cls="groupbox";text="数字区";left=33;top=91;right=362;bottom=358;edge=1;z=2};
  23. groupbox2={cls="groupbox";text="计算区";left=377;top=91;right=625;bottom=358;edge=1;z=13};
  24. static={cls="static";left=38;top=378;right=615;bottom=415;transparent=1;z=20}
  25. )
  26. /*}}*/

  27. import gdip;
  28. var makeimage = function (text){
  29.        
  30.         //图形对象graphics(可以看作是画板)
  31.         var graphics = gdip.graphics(  mainForm.static )  ;
  32.         graphics.clear(0xFFFFFFFF)
  33.         //创建刷子
  34.         var brush = gdip.solidBrush(0xFFFF0000);
  35.        
  36.         //创建FontFamily
  37.         var family = gdip.family("宋体");
  38.        
  39.         //创建stringFormat
  40.         var strformat = gdip.stringformat ( );
  41.        
  42.         //设置样式
  43.         strformat.align = 0/*_GdipStringAlignmentNear*/;
  44.        
  45.         //创建Font
  46.         var curFont = family.createFont(  35,1, 2/*_GdipUnitPixel*/)
  47.        
  48.         //设置文字抗据齿
  49.         graphics.smoothingMode = 4/*_GdipSmoothingModeAntiAlias*/ ;
  50.        
  51.         //消除走样,且边作平滑处理
  52.         graphics.textRenderingHint = 3/*_GdipTextRenderingHintAntiAliasGridFit*/;

  53.         //设置文字区域
  54.         rclayout = gdip.RECTF();
  55.         //rclayout.x = 33;
  56.         //rclayout.y = 400;
  57.         rclayout.width = 500 //在这里指的是宽度
  58.         rclayout.height = 150 //在这里指的是高度
  59.        
  60.        
  61.         graphics.drawString( text , curFont
  62.         , rclayout, strformat,brush);
  63.        
  64.         //删除所有GDI+对象   
  65.         brush.delete()
  66.         curFont.delete()
  67.         strformat.delete();
  68.         family.delete();
  69. }
  70. var onButtonCommand = function(id,event){
  71.        
  72.     mainForm.edit.text = mainForm.edit.text ++ owner.text;
  73. }
  74. for(name,ctrl in mainForm.eachControl("button") ){
  75.     ctrl.oncommand = onButtonCommand;
  76.    
  77. }
  78. mainForm.button15.oncommand = function(id,event){
  79.                 try{
  80.                         var all= mainForm.edit.text;
  81.                         mainForm.edit.text=eval(mainForm.edit.text);
  82.                         all =  all ++ "="++mainForm.edit.text
  83.                         makeimage(all);
  84.                 }
  85.                 catch(e){
  86.                         mainForm.msgbox("语句有误!");
  87.                         return ;
  88.                 }
  89.                
  90. }
  91. mainForm.button16.oncommand = function(id,event){
  92.         mainForm.edit.text=""
  93. }
  94. mainForm.isDialogMessage = function(hwnd,msg){

  95.     if(  msg.wParam == 0xD/*_VK_RETURN*/ ){
  96.         if( msg.message == 0x101/*_WM_KEYUP*/)
  97.          mainForm.button15.oncommand();
  98.         return true;
  99.     }
  100.     return win.isDialogMessage(hwnd,msg);
  101. }

  102. mainForm.show()
  103. return win.loopMessage();

复制代码


-----------------------------
更新:加入历史算式功能和菜单

  1. import win.ui;
  2. import win.ui.menu;
  3. /*DSG{{*/
  4. mainForm = win.form(text="西秦的练手计算器";right=920;bottom=462)
  5. mainForm.add(
  6. button={cls="button";text="+";left=392;top=112;right=492;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=14};
  7. button10={cls="button";text="1";left=245;top=235;right=335;bottom=285;z=11};
  8. button11={cls="button";text="0";left=46;top=295;right=134;bottom=345;z=12};
  9. button12={cls="button";text="-";left=499;top=112;right=599;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=15};
  10. button13={cls="button";text="*";left=392;top=210;right=492;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=16};
  11. button14={cls="button";text="/";left=499;top=210;right=599;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=17};
  12. button15={cls="button";text="=";left=392;top=304;right=600;bottom=348;font=LOGFONT(name='Times New Roman';h=-48);z=18};
  13. button16={cls="button";text="清除";left=245;top=295;right=335;bottom=345;z=19};
  14. button17={cls="button";text=".";left=145;top=295;right=235;bottom=345;z=21};
  15. button2={cls="button";text="7";left=45;top=115;right=135;bottom=165;z=3};
  16. button3={cls="button";text="8";left=145;top=115;right=235;bottom=165;z=4};
  17. button4={cls="button";text="9";left=245;top=115;right=335;bottom=165;z=5};
  18. button5={cls="button";text="6";left=45;top=175;right=135;bottom=225;z=6};
  19. button6={cls="button";text="5";left=145;top=175;right=235;bottom=225;z=7};
  20. button7={cls="button";text="4";left=245;top=175;right=335;bottom=225;z=8};
  21. button8={cls="button";text="3";left=47;top=235;right=134;bottom=285;z=9};
  22. button9={cls="button";text="2";left=145;top=235;right=235;bottom=285;z=10};
  23. edit={cls="edit";left=33;top=18;right=625;bottom=66;border=1;font=LOGFONT(h=-29);multiline=1;tabstop=1;transparent=1;z=1};
  24. edit2={cls="edit";left=646;top=32;right=883;bottom=385;multiline=1;readonly=1;transparent=1;z=23};
  25. groupbox={cls="groupbox";text="数字区";left=33;top=91;right=362;bottom=358;edge=1;z=2};
  26. groupbox2={cls="groupbox";text="计算区";left=377;top=91;right=625;bottom=358;edge=1;z=13};
  27. groupbox3={cls="groupbox";text="历史算式";left=635;top=14;right=891;bottom=402;edge=1;z=22};
  28. static={cls="static";left=38;top=378;right=615;bottom=415;transparent=1;z=20}
  29. )
  30. /*}}*/

  31. mainForm.popmenu = win.ui.popmenu(mainForm);//创建弹出菜单
  32. mainForm.popmenu.add('&清除历史算式',function(id){
  33.         mainForm.edit2.text="";
  34. });
  35. mainForm.popmenu.add();//分隔线
  36. mainForm.popmenu.add('&退出',function(id){ mainForm.close() })
  37. var menu = win.ui.menu(mainForm);//创建主菜单
  38. menu.add('文件',mainForm.popmenu)

  39. mainForm.aboutmenu= win.ui.popmenu(mainForm);
  40. mainForm.aboutmenu.add('关于我',function(id){
  41.         mainForm.msgbox("我是西秦公子")       
  42. }
  43. )
  44. mainForm.aboutmenu.add('关于Aardio',function(id){
  45.         mainForm.msgbox("自豪的采用Aardio")
  46. }
  47. )
  48. menu.add('关于',mainForm.aboutmenu);


  49. import gdip;
  50. var makeimage = function (text){
  51.        
  52.         //图形对象graphics(可以看作是画板)
  53.         var graphics = gdip.graphics(  mainForm.static )  ;
  54.         graphics.clear(0xFFFFFFFF)
  55.         //创建刷子
  56.         var brush = gdip.solidBrush(0xFFFF0000);
  57.        
  58.         //创建FontFamily
  59.         var family = gdip.family("宋体");
  60.        
  61.         //创建stringFormat
  62.         var strformat = gdip.stringformat ( );
  63.        
  64.         //设置样式
  65.         strformat.align = 0/*_GdipStringAlignmentNear*/;
  66.        
  67.         //创建Font
  68.         var curFont = family.createFont(  35,1, 2/*_GdipUnitPixel*/)
  69.        
  70.         //设置文字抗据齿
  71.         graphics.smoothingMode = 4/*_GdipSmoothingModeAntiAlias*/ ;
  72.        
  73.         //消除走样,且边作平滑处理
  74.         graphics.textRenderingHint = 3/*_GdipTextRenderingHintAntiAliasGridFit*/;

  75.         //设置文字区域
  76.         rclayout = gdip.RECTF();
  77.         //rclayout.x = 33;
  78.         //rclayout.y = 400;
  79.         rclayout.width = 500 //在这里指的是宽度
  80.         rclayout.height = 150 //在这里指的是高度
  81.        
  82.        
  83.         graphics.drawString( text , curFont
  84.         , rclayout, strformat,brush);
  85.        
  86.         //删除所有GDI+对象   
  87.         brush.delete()
  88.         curFont.delete()
  89.         strformat.delete();
  90.         family.delete();
  91. }
  92. var onButtonCommand = function(id,event){
  93.        
  94.     mainForm.edit.text = mainForm.edit.text ++ owner.text;
  95. }
  96. for(name,ctrl in mainForm.eachControl("button") ){
  97.     ctrl.oncommand = onButtonCommand;
  98.    
  99. }
  100. mainForm.button15.oncommand = function(id,event){
  101.                 try{
  102.                         var all= mainForm.edit.text;
  103.                         mainForm.edit.text=eval(mainForm.edit.text);
  104.                         all =  all ++ "="++mainForm.edit.text
  105.                         makeimage(all);
  106.                         mainForm.edit2.print(all)
  107.                 }
  108.                 catch(e){
  109.                         mainForm.msgbox("语句有误!");
  110.                         return ;
  111.                 }
  112.                
  113. }
  114. mainForm.button16.oncommand = function(id,event){
  115.         mainForm.edit.text=""
  116. }
  117. mainForm.isDialogMessage = function(hwnd,msg){

  118.     if(  msg.wParam == 0xD/*_VK_RETURN*/ ){
  119.         if( msg.message == 0x101/*_WM_KEYUP*/)
  120.          mainForm.button15.oncommand();
  121.         return true;
  122.     }
  123.     return win.isDialogMessage(hwnd,msg);
  124. }

  125. mainForm.show()
  126. return win.loopMessage();

复制代码

166

主题

2153

回帖

1万

积分

管理员

积分
13051
发表于 2016-6-24 22:44:26 | 显示全部楼层
key.hook 是全局键盘钩子,这个不要随便用。

一般如果你是要添加快捷键,用  win.ui.accelerator (参考函数提示)
如果要添加全局快捷键 - 也应当使用 winform.reghotkey()

如果是希望按回车键默认调用哪个按钮。
在窗体设计器中右键点该按钮,选择排序到最后面就可以,这个是默认支持的。

也可以这样写:
/*
对话框上按回车键触发事件
*/

mainForm.isDialogMessage =
function(hwnd,msg){

   
if(  msg.wParam == 0xD/*_VK_RETURN*/ ){
   
        
if( msg.message == 0x101/*_WM_KEYUP*/)  
            mainForm.button15.oncommand();
//调用按钮事件
            
        
return true; //不要再处理该消息
    }
   
return win.isDialogMessage(hwnd,msg);
}



0

主题

6

回帖

48

积分

新手入门

积分
48
发表于 2016-6-25 12:08:47 | 显示全部楼层
基础上又添加些,按键没做,初学望支持!!

  1. import win.ui;
  2. /*DSG{{*/
  3. mainForm = win.form(text="Aardio 计算器";right=661;bottom=376;border="thin")
  4. mainForm.add(
  5. button={cls="button";text="+";left=392;top=112;right=492;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=14};
  6. button10={cls="button";text="1";left=245;top=235;right=335;bottom=285;z=11};
  7. button11={cls="button";text="0";left=46;top=295;right=235;bottom=345;z=12};
  8. button12={cls="button";text="-";left=499;top=112;right=599;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=15};
  9. button13={cls="button";text="*";left=392;top=210;right=492;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=16};
  10. button14={cls="button";text="/";left=499;top=210;right=599;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=17};
  11. button15={cls="button";text="=";left=390;top=303;right=600;bottom=347;font=LOGFONT(name='Times New Roman';h=-48);z=18};
  12. button16={cls="button";text="清除";left=245;top=295;right=335;bottom=345;z=19};
  13. button2={cls="button";text="7";left=45;top=115;right=135;bottom=165;z=3};
  14. button3={cls="button";text="8";left=145;top=115;right=235;bottom=165;z=4};
  15. button4={cls="button";text="9";left=245;top=115;right=335;bottom=165;z=5};
  16. button5={cls="button";text="6";left=45;top=175;right=135;bottom=225;z=6};
  17. button6={cls="button";text="5";left=145;top=175;right=235;bottom=225;z=7};
  18. button7={cls="button";text="4";left=245;top=175;right=335;bottom=225;z=8};
  19. button8={cls="button";text="3";left=47;top=235;right=134;bottom=285;z=9};
  20. button9={cls="button";text="2";left=145;top=235;right=235;bottom=285;z=10};
  21. edit={cls="edit";left=33;top=18;right=625;bottom=69;edge=1;font=LOGFONT(h=-29);multiline=1;z=1};
  22. groupbox={cls="groupbox";text="数字区";left=33;top=91;right=362;bottom=358;edge=1;z=2};
  23. groupbox2={cls="groupbox";text="计算区";left=377;top=91;right=625;bottom=358;edge=1;z=13}
  24. )
  25. /*}}*/
  26. var op=true,res=false, qian="";
  27. var onButtonCommand = function(id,event){
  28.         if(res){
  29.         mainForm.edit.text =owner.text;       
  30.         res=false;
  31.         }else {
  32.         mainForm.edit.text = mainForm.edit.text ++ owner.text;
  33.         }
  34.     op=true;
  35.     qian= mainForm.edit.text;
  36. }
  37. for(name,ctrl in mainForm.eachControl("button") ){
  38.     ctrl.oncommand = onButtonCommand;           
  39.     }

  40. var suanshuCommand =function(id,event){
  41.         res=false;
  42.         if(op){
  43.                 mainForm.edit.text = mainForm.edit.text ++ owner.text;
  44.                 op=false;
  45.         }else {
  46.                 if(qian ==null){
  47.                         mainForm.edit.text=owner.text;
  48.                 }else {
  49.                         mainForm.edit.text=qian ++ owner.text;
  50.                 }
  51.         }       
  52. }
  53. mainForm.button12.oncommand=suanshuCommand
  54. mainForm.button13.oncommand=suanshuCommand
  55. mainForm.button14.oncommand=suanshuCommand
  56. mainForm.button.oncommand=suanshuCommand   
  57. mainForm.button15.oncommand = function(id,event){
  58. try{
  59.                 mainForm.edit.text=eval(mainForm.edit.text);
  60.         }catch(e){
  61.                 var edtext =mainForm.edit.text ;
  62.                 if(edtext=="+" || edtext=="-" || edtext=="*" || edtext=="/" ){
  63.                         mainForm.edit.text="0";
  64.                         return 0;
  65.                 }
  66.                 var v = string.match( edtext , "^(\D)" );
  67.                 if(v){
  68.                         edtext="0" ++ edtext;
  69.                 }else {
  70.                         edtext="0+" ++ edtext;
  71.                 }
  72.                 mainForm.edit.text=eval( string.match(edtext,"\d.*\d"))
  73.         }               
  74.                 qian=mainForm.edit.text;
  75.                 res=true;
  76. }
  77. mainForm.button16.oncommand = function(id,event){
  78.         mainForm.edit.text=""
  79.         qian=""
  80. }
  81. mainForm.show()
  82. return win.loopMessage();
复制代码

0

主题

6

回帖

48

积分

新手入门

积分
48
发表于 2016-6-26 14:53:19 | 显示全部楼层
yqs2016cl 发表于 2016-6-25 12:08
基础上又添加些,按键没做,初学望支持!!

跟风的加了些,脑袋有点转不动,添加的是reghotkey,但是用了之后,本界面显示没问题,切换到别的界面按了键还是在计算器上显示,如果用消息回调mainForm.wndproc后,有时message是229 还有按键能用之后切换用鼠标按几下,再用键盘就不管用了,额~~~~~~~
  1. import win.ui;
  2. /*DSG{{*/
  3. mainForm = win.form(text="Aardio 计算器";right=661;bottom=376;border="thin")
  4. mainForm.add(
  5. button={cls="button";text="+";left=392;top=112;right=492;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=15};
  6. button10={cls="button";text="1";left=245;top=235;right=335;bottom=285;z=12};
  7. button11={cls="button";text="0";left=46;top=295;right=133;bottom=345;z=13};
  8. button12={cls="button";text="-";left=499;top=112;right=599;bottom=202;font=LOGFONT(name='微软雅黑';h=-48);z=16};
  9. button13={cls="button";text="*";left=392;top=210;right=492;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=17};
  10. button14={cls="button";text="/";left=499;top=210;right=599;bottom=300;font=LOGFONT(name='微软雅黑';h=-48);z=18};
  11. button15={cls="button";text="=";left=390;top=303;right=600;bottom=347;font=LOGFONT(name='Times New Roman';h=-48);z=1};
  12. button16={cls="button";text="清除";left=245;top=295;right=335;bottom=345;z=19};
  13. button17={cls="button";text=".";left=145;top=295;right=232;bottom=345;font=LOGFONT(h=-29);valign="top";z=20};
  14. button2={cls="button";text="7";left=45;top=115;right=135;bottom=165;z=4};
  15. button3={cls="button";text="8";left=145;top=115;right=235;bottom=165;z=5};
  16. button4={cls="button";text="9";left=245;top=115;right=335;bottom=165;z=6};
  17. button5={cls="button";text="6";left=45;top=175;right=135;bottom=225;z=7};
  18. button6={cls="button";text="5";left=145;top=175;right=235;bottom=225;z=8};
  19. button7={cls="button";text="4";left=245;top=175;right=335;bottom=225;z=9};
  20. button8={cls="button";text="3";left=47;top=235;right=134;bottom=285;z=10};
  21. button9={cls="button";text="2";left=145;top=235;right=235;bottom=285;z=11};
  22. edit={cls="edit";left=33;top=18;right=625;bottom=69;disabled=1;edge=1;font=LOGFONT(h=-29);z=2};
  23. groupbox={cls="groupbox";text="数字区";left=33;top=91;right=362;bottom=358;edge=1;z=3};
  24. groupbox2={cls="groupbox";text="计算区";left=377;top=91;right=625;bottom=358;edge=1;z=14}
  25. )
  26. /*}}*/

  27. var op=true,res=false, qian="" ,dian=false; //op 为+-*/开关    res为 等号开关  qian 为 按(+-*/)的上一步的文本内容 dian 判断小数点位置开关
  28. var onButtonCommand = function(id,event){
  29.         dian=false;
  30.         if(res){
  31.                 //判断是否按了=号 是! 覆盖文本框 否! 在后面添加
  32.                 mainForm.edit.text =owner.text;       
  33.                 res=false;
  34.         }else {
  35.                 mainForm.edit.text = mainForm.edit.text ++ owner.text;
  36.         }
  37.     op=true;
  38.     qian= mainForm.edit.text;
  39. }
  40. var onButtonCommand2 = function(id){
  41.         dian=false;
  42.         if(res){
  43.                 //判断是否按了=号 是! 覆盖文本框 否! 在后面添加
  44.                 mainForm.edit.text =id;       
  45.                 res=false;
  46.         }else {
  47.                 mainForm.edit.text = mainForm.edit.text ++ id;
  48.         }
  49.     op=true;
  50.     qian= mainForm.edit.text;
  51. }

  52. for(name,ctrl in mainForm.eachControl("button") ){
  53.     ctrl.oncommand = onButtonCommand;           
  54.     }

  55. var suanshuCommand =function(id,event){
  56.         res=false;dian=false;
  57.         if(op){
  58.                 mainForm.edit.text = mainForm.edit.text ++ owner.text;
  59.                 op=false;
  60.         }else {
  61.                 if(qian ==null){
  62.                         mainForm.edit.text=owner.text;
  63.                 }else {
  64.                         mainForm.edit.text=qian ++ owner.text;
  65.                 }
  66.         }       
  67. }
  68. var suanshuCommand2 =function(id){
  69.         res=false;dian=false;
  70.         if(op){
  71.                 mainForm.edit.text = mainForm.edit.text ++ id;
  72.                 op=false;
  73.         }else {
  74.                 if(qian ==null){
  75.                         mainForm.edit.text=id;
  76.                 }else {
  77.                         mainForm.edit.text=qian ++ id;
  78.                 }
  79.         }       
  80. }
  81. mainForm.button12.oncommand=suanshuCommand
  82. mainForm.button13.oncommand=suanshuCommand
  83. mainForm.button14.oncommand=suanshuCommand
  84. mainForm.button.oncommand=suanshuCommand  
  85. mainForm.button17.oncommand = function(id,event){
  86.         if(res=true){
  87.                 mainForm.edit.text=""
  88.                 res=false;
  89.         }
  90.         if(dian=false){
  91.         if(mainForm.edit.text == ""){
  92.                 mainForm.edit.text="0."
  93.                 dian=true
  94.                 return 0;
  95.         }
  96.         if(op == false){
  97.                 mainForm.edit.text=mainForm.edit.text ++ "0."
  98.                 dian=true
  99.                 return 0;
  100.         }
  101.         mainForm.edit.text=mainForm.edit.text ++ "."
  102.         dian=true
  103.         }
  104. }  
  105. mainForm.button15.oncommand = function(id,event){
  106. try{
  107.                 mainForm.edit.text=eval(mainForm.edit.text);
  108.         }catch(e){
  109.                 var edtext =mainForm.edit.text ;
  110.                 if(edtext=="+" || edtext=="-" || edtext=="*" || edtext=="/" ){
  111.                         mainForm.edit.text="0";
  112.                         return 0;
  113.                 }
  114.                 var v = string.match( edtext , "^(\D)" );
  115.                 if(v){
  116.                         edtext="0" ++ edtext;
  117.                 }else {
  118.                         edtext="0+" ++ edtext;
  119.                 }
  120.                 mainForm.edit.text=eval( string.match(edtext,"\d.*\d"))
  121.         }               
  122.                 qian=mainForm.edit.text;
  123.                 res=true;
  124. }
  125. mainForm.button16.oncommand = function(id,event){
  126.         mainForm.edit.text=""
  127.         qian=""
  128. }
  129. /**
  130. mainForm.wndproc = function(hwnd,message,wParam,lParam){
  131.         select( message ) {
  132.                 case 256/*_WM_RBUTTONUP*/{
  133.                        
  134.                 select(wParam) {
  135.                                 case 96 {
  136.                                          onButtonCommand2("0")
  137.                                 }
  138.                                 case 97 {
  139.                                          onButtonCommand2("1")
  140.                                 }
  141.                                 case 98 {
  142.                                          onButtonCommand2("2")
  143.                                 }
  144.                                 case 99 {
  145.                                          onButtonCommand2("3")
  146.                                 }
  147.                                 case 100 {
  148.                                          onButtonCommand2("4")
  149.                                 }
  150.                                 case 101 {
  151.                                          onButtonCommand2("5")
  152.                                 }
  153.                                 case 102 {
  154.                                          onButtonCommand2("6")
  155.                                 }
  156.                                 case 103 {
  157.                                          onButtonCommand2("7")
  158.                                 }
  159.                                 case 104 {
  160.                                          onButtonCommand2("8")
  161.                                 }
  162.                                 case 105 {
  163.                                          onButtonCommand2("9")
  164.                                 }
  165.                                 case 106 {
  166.                                          suanshuCommand2("*")
  167.                                 }
  168.                                 case 107 {
  169.                                          suanshuCommand2("+")
  170.                                 }
  171.                                 case 111 {
  172.                                          suanshuCommand2("/")
  173.                                 }
  174.                                 case 109 {
  175.                                          suanshuCommand2("-")
  176.                                 }
  177.                                 case 110 {
  178.                                          mainForm.button17.oncommand(0,0)
  179.                                 }
  180.                         }       
  181.                 }
  182.         }
  183. }
  184. **/
  185. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("0")},0,96)
  186. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("1")},0,97)
  187. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("2")},0,98)
  188. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("3")},0,99)
  189. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("4")},0,100)
  190. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("5")},0,101)
  191. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("6")},0,102)
  192. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("7")},0,103)
  193. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("8")},0,104)
  194. mainForm.reghotkey( function(id,mod,vk){onButtonCommand2("9")},0,105)
  195. mainForm.reghotkey( function(id,mod,vk){suanshuCommand2("*")},0,106)
  196. mainForm.reghotkey( function(id,mod,vk){suanshuCommand2("+")},0,107)
  197. mainForm.reghotkey( function(id,mod,vk){suanshuCommand2("/")},0,111)
  198. mainForm.reghotkey( function(id,mod,vk){suanshuCommand2("-")},0,109)
  199. mainForm.reghotkey( function(id,mod,vk){mainForm.button17.oncommand()},0,110)
  200. mainForm.show()
  201. return win.loopMessage();
复制代码
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

手机版|未经许可严禁引用或转载本站文章|aardio.com|aardio 官方社区 ( 皖ICP备09012014号 )

GMT+8, 2025-7-23 05:52 , Processed in 0.066667 second(s), 25 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表