关于托盘跟随系统启动问题(图+源码) [已解决]
本帖最后由 yingf20 于 2010-9-5 22:01 编辑;--------------------------程序源码是转载别人的--------------------------------------
#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Icon=F:\Icon\16\0052.ICO
#AutoIt3Wrapper_Outfile=TrayMenu.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=托盘菜单
#AutoIt3Wrapper_Res_Description=带配置文件的托盘菜单
#AutoIt3Wrapper_Res_Fileversion=0.0.0.2
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p
#AutoIt3Wrapper_Res_LegalCopyright=开源
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <File.au3>
$iniFile = "TrayMenu.ini"
$varTrayMenuList = IniReadSection($iniFile, "TrayMenu")
$varTrayItemList = IniReadSection($iniFile, "TrayItem")
$tempFile = _TempFile()
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
TraySetClick(16)
If @error Then
MsgBox(4096, "", "错误, 读取INI文件失败.")
Exit
Else
For $i = 1 To $varTrayMenuList
$menu = TrayCreateMenu($varTrayMenuList[$i])
For $j = 1 To $varTrayItemList
If ($varTrayItemList[$j] == $varTrayMenuList[$i]) Then
$temp = StringSplit($varTrayItemList[$j], ";")
$tid = TrayCreateItem($temp, $menu)
TrayItemSetOnEvent($tid, "RunApp")
IniWrite($tempFile, "MenuKey", $tid, $temp)
EndIf
Next
Next
EndIf
$varMenuKeyList = IniReadSection($tempFile, "MenuKey")
TrayCreateItem("")
$exititem = TrayCreateItem("退出")
TrayItemSetOnEvent($exititem, "ExitFun")
TraySetState()
While 1
Sleep(500)
WEnd
Exit
Func RunApp()
For $k = 1 To $varMenuKeyList
If ($varMenuKeyList[$k] == @TRAY_ID) Then
RunWait($varMenuKeyList[$k])
EndIf
Next
EndFunc ;==>RunApp
Func ExitFun()
Exit
EndFunc ;==>ExitFun
;---------------------------------------------------------程序源码------------------------------------------------
;---------------------------------------------------------配置文件TrayMenu.ini------------------------------------
;
;1=工具菜单
;2=程序相关
;
;1=Total Uninstall;Tools\TU\tu.exe
;1=Scite;Tools\Scite\Scite.exe
;1=MsiTools;Tools\MsiTools\MsiTools.exe
;1=百度一下;Tools\TheWorld\TheWorld.exe http://www.baidu.com
;2=程序源码;Tools\TrayMenuSrc\TheWorld.exe http://www.baidu.com
;---------------------------------------------------------配置文件TrayMenu.ini------------------------------------我想在托盘程序菜单里加个[跟随系统启动]这项上去。应该怎写呢?
知道的帮忙一下。在此谢谢!看贴者就顶一下。
在此谢谢[水木子]版主帮忙解决! 本帖最后由 水木子 于 2010-9-5 17:38 编辑
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("Form1", 280, 250)
$Checkbox1 = GUICtrlCreateCheckbox("跟随系统启动", 80, 80, 90, 17)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
Case $Checkbox1
If BitAND($Checkbox1, $GUI_CHECKED) Then
RegWrite('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', @ScriptName, 'REG_SZ', '"' & @ScriptFullPath & '" /AUTO')
MsgBox(0, '状态:', ' 已添加随系统启动! ')
Else
RegDelete('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', @ScriptName)
MsgBox(0, '状态:', ' 已删除随系统启动! ')
EndIf
EndSwitch
WEnd 楼上的不错。RegWrite('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', @ScriptName, 'REG_SZ', '"' & @ScriptFullPath & '" /AUTO')
主要是这个注册表文件。 收藏一下! #include <Constants.au3>
Opt("TrayMenuMode", 1)
Local $sRegPath = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
GUICreate("Form1", 280, 250)
$Yes = TrayCreateItem("跟随系统启动")
$No = TrayCreateItem("不随系统启动")
$exit = TrayCreateItem("退出")
If RegRead($sRegPath, @ScriptName) <> '' Then
TrayItemSetState($Yes, $TRAY_CHECKED)
Else
TrayItemSetState($No, $TRAY_CHECKED)
EndIf
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
EndSwitch
$msg = TrayGetMsg()
Select
Case $msg = $exit
Exit
Case $msg = $Yes
RegWrite($sRegPath, @ScriptName, 'REG_SZ', '"' & @ScriptFullPath & '" /AUTO')
MsgBox(0, '状态:', '跟随系统启动')
Case $msg = $No
RegDelete($sRegPath, @ScriptName)
MsgBox(0, '状态:', '不随系统启动')
EndSelect
WEnd 回复 1# yingf20
学习了,谢谢! 本帖最后由 zhurongfei 于 2011-4-27 21:55 编辑
回复 5# 水木子
这句RegDelete($sRegPath, @ScriptName), 不对吧。不能删除启动项 学习................... 谢谢分享,做个记号 正需要,学习中
页:
[1]