关于定时关机的问题【已解决】
本帖最后由 风过无痕 于 2017-10-12 12:18 编辑#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("定时关机", 203, 133, -1, -1)
$Group1 = GUICtrlCreateGroup("时间设置", 8, 8, 185, 65)
$Combo1 = GUICtrlCreateCombo("", 16, 32, 41, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|00", "23")
$Label1 = GUICtrlCreateLabel("时", 64, 32, 36, 17)
$Combo2 = GUICtrlCreateCombo("", 104, 32, 41, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
GUICtrlSetData(-1, "05|10|15|20|25|30|35|40|45|50|55|00", "00")
$Label2 = GUICtrlCreateLabel("分", 152, 32, 36, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("开机启动", 10, 88, 100, 33)
$Button1 = GUICtrlCreateButton("执行", 120, 88, 60, 35)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
$item1 = TrayCreateItem("退出程序")
TrayItemSetOnEvent(-1, "_Exit")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case -4
GUISetState(@SW_HIDE, $Form1)
Opt("TrayIconHide", 0)
Case $Button1
GUANJI()
EndSwitch
WEnd
Func GUANJI()
; GUICtrlSetData($Button1, "取消")
$SHI = GUICtrlRead($Combo1)
$FEN = GUICtrlRead($Combo2)
While 1
; If GUICtrlRead($Button1) = "执行" Then;1.去掉这个IF就能执行了,不知道原因2.关机是能执行了,但是点窗口没有任何反映 除了最小化之外的其他任何操作没用
If @HOUR = $SHI And @MIN = $FEN And @SEC = 00 Then;如果系统时间为12小时制的话,这个就不起作用了?如果是12小时的话应当怎么写?
Shutdown(0 + 4);此处为方便测试改成注销了
EndIf
; Else;
; EndIf;
WEnd
EndFunc ;==>GUANJI
Func _Exit()
Exit
EndFunc ;==>_Exit这是我的简单的代码,开机启动的那个没加,后面加
现在的问题是:
1.当我把注释行取消了,就可以用了,但是前提是系统时间为24小时制的,如果是12小时的话应当怎么写?或者是怎么判断?
2.去掉注释行内容后,当点击“执行”后,按钮变为“取消”,此时点击“取消”或者窗口的关闭都是没有任何作用的?
3.怎么修改才能实现,当点击取消时,按钮恢复成“执行”?,但是在已经定时的状态下点击“关闭”时,程序不退出?
问题困惑一天了,请各位帮忙看看吧 谢谢! 回复 1# 风过无痕 #include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
#region ### START Koda GUI section ### Form=
Local $bool_shutdown = False
$Form1 = GUICreate("定时关机", 203, 133, -1, -1)
$Group1 = GUICtrlCreateGroup("时间设置", 8, 8, 185, 65)
$Combo1 = GUICtrlCreateCombo("", 16, 32, 41, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|00", "23")
$Label1 = GUICtrlCreateLabel("时", 64, 32, 36, 17)
$Combo2 = GUICtrlCreateCombo("", 104, 32, 41, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
GUICtrlSetData(-1, "05|10|15|20|25|30|35|40|45|50|55|00", "00")
$Label2 = GUICtrlCreateLabel("分", 152, 32, 36, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("开机启动", 10, 88, 100, 33)
$Button1 = GUICtrlCreateButton("执行", 120, 88, 60, 35)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
$item1 = TrayCreateItem("退出程序")
TrayItemSetOnEvent(-1, "_Exit")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
_Exit()
Case -4
GUISetState(@SW_HIDE, $Form1)
Opt("TrayIconHide", 0)
Case $Button1
If GUICtrlRead($Button1) = "执行" Then ; if $bool_shutdown = False ; 也可以
GUICtrlSetData($Button1, "取消")
AdlibRegister('_shutdown', 50)
$bool_shutdown = True
Else
GUICtrlSetData($Button1, "执行")
AdlibUnRegister('_shutdown')
$bool_shutdown = False
EndIf
EndSwitch
WEnd
Func _shutdown()
$hour = GUICtrlRead($Combo1)
$min = GUICtrlRead($Combo2)
$current_time = StringSplit(_NowTime(4), ':')
If Not IsArray($current_time) Then Return
If $hour = $current_time And $min = $current_time Then
MsgBox(0, 'msg', '执行成功!', 0, $Form1)
;Shutdown(0 + 4)
EndIf
EndFunc ;==>_shutdown
Func _Exit()
If $bool_shutdown = True Then Return MsgBox(16, 'Err', '请先取消定时关机计划!', 0, $Form1)
Exit
EndFunc ;==>_Exit 回复风过无痕
user3000 发表于 2013-6-24 19:48 http://www.autoitx.com/images/common/back.gif
谢谢了 完全满足我的要求
研究一下{:face (239):}
页:
[1]