TC官方合作论坛

标题: 时间计时控制小源代码一枚 [打印本页]

作者: 裤裆里面有杀气    时间: 2014-10-12 01:41
标题: 时间计时控制小源代码一枚
  1. namespace __Timer
  2. //默认空间
  3. var flag = false,tHandle
  4. var second=0,minute=0,hour=0

  5. //开始按钮_点击操作
  6. function start_click()
  7.    
  8. endfunction

  9. //退出按钮_点击操作
  10. function exit_click()
  11.     if(thread.closethread(tHandle))
  12.         tHandle  = 0
  13.         help.exit()
  14.     else
  15.         if(flag == true)
  16.             help.messagebox("线程关闭错误")
  17.             help.exit()
  18.         else
  19.             help.exit()
  20.         endif
  21.         
  22.     endif
  23. endfunction


  24. function TimeThread_Proc()
  25.     //秒分时
  26.    
  27.     var second_str ="00",minute_str="00",hour_str="00"
  28.     while(flag)
  29.         edit.settext("编辑框_内容",hour_str & ":" &minute_str & ":" &second_str)
  30.         help.sleep(1000)
  31.         second++
  32.         if(second == 60)
  33.             second = 0
  34.             minute = minute + 1
  35.         endif
  36.         
  37.         if(minute == 60)
  38.             minute = 0
  39.             hour = hour + 1
  40.         endif
  41.         
  42.         second_str = type.cstring(second)
  43.         minute_str = type.cstring(minute)
  44.         hour_str = type.cstring(hour)
  45.         if(str.strleng(second_str) == 1)//个位状态
  46.             second_str ="0"&second_str
  47.         endif
  48.         if(str.strleng(minute_str) == 1)//个位状态
  49.             minute_str = "0"&minute_str
  50.         endif
  51.         if(str.strleng(hour_str) == 1)//个位状态
  52.             hour_str = "0"&hour_str
  53.         endif
  54.         
  55.     endwhile
  56.     //
  57. endfunction



  58. function StopTime_click()
  59.     //这里添加你要执行的代码
  60.    
  61.     if(tHandle>0)
  62.         var state
  63.         
  64.         state=button.gettext("StopTime")
  65.         if(state == "停止计时")
  66.             //flag =false
  67.             thread.suspendthread(tHandle)
  68.             button.settext("StopTime","继续计时")
  69.         endif
  70.         
  71.         if (state == "继续计时")
  72.             //flag = true
  73.             thread.resumethread(tHandle)
  74.             button.settext("StopTime","停止计时")
  75.         endif
  76.         
  77.     else
  78.         help.messagebox("没有找到句柄,你还没有开启线程")
  79.     endif
  80.    
  81. endfunction


  82. function StartTime_click()
  83.     //这里添加你要执行的代码
  84.     if(flag == true)
  85.         help.messagebox("已开启计时,请不要重复开启!")
  86.     else
  87.         flag = true
  88.         tHandle = thread.beginthread("__Timer.TimeThread_Proc","")   
  89.     endif
  90.    
  91. endfunction

  92. endnamespace
  93. //空间结束
复制代码


学习一进一出哪里好?官方学院找EZ.

大家好,才是真的好





欢迎光临 TC官方合作论坛 (http://bbs.52tc.co/) Powered by Discuz! X3.1