【已解决】GUI 单个BUTTON 启动,暂停实现相应功能问题请教
本帖最后由 funco 于 2013-3-6 23:14 编辑下面是我写的一个终结程序的代码。
可以自定义快捷键CTRL或ALT+任意键盘去结束想要结束的进程。
但是在关于BUTTON点击的方面有一个小BUG.
我想实现当我点击启动BUTTON的时候,程式可以实现快捷键终止功能,同时启动BUTTON变成暂停,点击暂停时,BUTTON变成启动,同时暂停终止进程功能。
而实际是当我点击暂停后,程式仍会有一次可以终止的功能在。
下面的程序代码因为这个BUG我改成退出了。有试过用_ISPRESSED去替代HOTKEYSET.但是会出现部分热键冲突的BUG,如设定CTRL+S为终止键时,会有机率无法正常终止。
-----------------------------
Opt("TrayAutoPause",0)
Opt("TrayMenuMode",1)
Dim $FLAG=0
#include <GUIConstants.au3>
Dim $Button2
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("终结者", 256, 240, 184, 125)
GUISetCursor (2)
GUISetFont(12, 400, 0,"标楷体")
$input1=GUICtrlCreateInput("Winword.EXE", 16, 64, 201, 27)
GUICtrlSetFont(-1, 12, 400, 0, "Cambria")
$Label1 = GUICtrlCreateLabel("请输入需要终结的进程名", 16, 16, 224, 23)
GUICtrlSetFont(-1, 14, 400, 0, "标楷体")
$Label2 = GUICtrlCreateLabel("Ex:WinWord.exe", 16, 40, 72, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Cambria")
$Label3 = GUICtrlCreateLabel("请选择热键组合", 18, 96, 144, 23)
GUICtrlSetFont(-1, 14, 400, 0, "标楷体")
$Label4 = GUICtrlCreateLabel("+", 100, 120, 13, 24)
$Ctrl = GUICtrlCreateCombo("", 16, 120, 73, 25)
GUICtrlSetData(-1,"Ctrl|Alt","Ctrl")
GUICtrlSetFont(-1, 10, 400, 0, "Calibri")
GUICtrlSetCursor (-1, 2)
$input2=GUICtrlCreateInput("S", 120, 120, 97, 23)
GUICtrlSetFont(-1, 10, 400, 0, "Calibri")
$Button1 = GUICtrlCreateButton("启动", 16, 160, 209, 49, 0)
GUICtrlSetFont(-1, 14, 400, 0, "标楷体")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$TMSG=TrayGetMsg ()
Switch $TMSG 抱歉,实然发现代码没贴全
Opt("TrayAutoPause",0)
Opt("TrayMenuMode",1)
Dim $FLAG=0
#include <GUIConstants.au3>
Dim $Button2
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("终结者", 256, 240, 184, 125)
GUISetCursor (2)
GUISetFont(12, 400, 0,"标楷体")
$input1=GUICtrlCreateInput("Winword.EXE", 16, 64, 201, 27)
GUICtrlSetFont(-1, 12, 400, 0, "Cambria")
$Label1 = GUICtrlCreateLabel("请输入需要终结的进程名", 16, 16, 224, 23)
GUICtrlSetFont(-1, 14, 400, 0, "标楷体")
$Label2 = GUICtrlCreateLabel("Ex:WinWord.exe", 16, 40, 72, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Cambria")
$Label3 = GUICtrlCreateLabel("请选择热键组合", 18, 96, 144, 23)
GUICtrlSetFont(-1, 14, 400, 0, "标楷体")
$Label4 = GUICtrlCreateLabel("+", 100, 120, 13, 24)
$Ctrl = GUICtrlCreateCombo("", 16, 120, 73, 25)
GUICtrlSetData(-1,"Ctrl|Alt","Ctrl")
GUICtrlSetFont(-1, 10, 400, 0, "Calibri")
GUICtrlSetCursor (-1, 2)
$input2=GUICtrlCreateInput("S", 120, 120, 97, 23)
GUICtrlSetFont(-1, 10, 400, 0, "Calibri")
$Button1 = GUICtrlCreateButton("启动", 16, 160, 209, 49, 0)
GUICtrlSetFont(-1, 14, 400, 0, "标楷体")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$TMSG=TrayGetMsg ()
Switch $TMSG
Case $TRAY_EVENT_PRIMARYDOUBLE
GUISetState(@SW_SHOW)
EndSwitch
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
If $FLAG=0 Then
$Bre=1
$FLAG=1
AdlibEnable("BEGIN")
GUICtrlSetData($Button1,"退出")
GUISetState(@SW_HIDE)
TrayTip("","I am Working Here.",1)
Sleep(500)
Else
Exit
$bre=0
$FLAG=0
AdlibDisable()
GUICtrlSetData($Button1,"启动")
EndIf
EndSwitch
WEnd
Func BEGIN()
$s1=StringLower(GUICtrlRead($input2))
$s2=GUICtrlRead($Ctrl)
Switch $s2
Case "Ctrl"
HotKeySet("^"&$s1,"bre")
Case "Alt"
HotKeySet("!"&$s1,"bre")
EndSwitch
EndFunc
Func bre()
$s=GUICtrlRead($input1)
HotKeySet(@HotKeyPressed)
While ProcessExists($s)
ProcessClose($s)
WEnd
EndFunc
页:
[1]