本帖最后由 虎虎虎 于 2012-2-26 11:19 编辑
源码来自本站,地址分别是:
一个可以读取配置文件的托盘源码(原创)]
关于托盘跟随系统启动问题(图+源码) [已解决]
运行没有报错,设置随系统启动开机时报错。
错误截图:
修改后源码:#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=C:\Windows\system32\SHELL32.dll|-25
#AutoIt3Wrapper_Outfile=常用托盘程序.exe
#AutoIt3Wrapper_Res_Comment=常用托盘程序
#AutoIt3Wrapper_Res_Description=常用托盘程序1.0
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=常用托盘程序1.0
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
;---------------------------------------------------------程序源码------------------------------------------------
#include <File.au3>
#include <Constants.au3>
$iniFile = "TrayMenu.ini"
$varTrayMenuList = IniReadSection($iniFile, "TrayMenu")
$varTrayItemList = IniReadSection($iniFile, "TrayItem")
$tempFile = _TempFile()
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode",3)
TraySetClick(16)
If @error Then
MsgBox(4096, "", "错误, 读取INI文件失败.")
Exit
Else
For $i = 1 To $varTrayMenuList[0][0]
$menu = TrayCreateMenu($varTrayMenuList[$i][1])
For $j = 1 To $varTrayItemList[0][0]
If ($varTrayItemList[$j][0] == $varTrayMenuList[$i][0]) Then
$temp = StringSplit($varTrayItemList[$j][1], ";")
$tid = TrayCreateItem($temp[1], $menu)
TrayItemSetOnEvent($tid, "RunApp")
IniWrite($tempFile, "TrayMenu", $tid, $temp[2])
EndIf
Next
Next
EndIf
$varMenuKeyList = IniReadSection($tempFile, "TrayMenu")
;===================================================================
Local $sRegPath = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
TrayCreateItem("")
$MenRun = TrayCreateMenu("随机启动")
$Yes = TrayCreateItem("跟随系统启动",$MenRun)
$No = TrayCreateItem("不随系统启动",$MenRun)
If RegRead($sRegPath, @ScriptName) <> '' Then
TrayItemSetState($Yes, $TRAY_CHECKED)
Else
TrayItemSetState($No, $TRAY_CHECKED)
EndIf
;===================================================================
TrayCreateItem("")
$exititem = TrayCreateItem("退出")
TrayItemSetOnEvent($Yes, "RunFun")
TrayItemSetOnEvent($No, "NoRunFun")
TrayItemSetOnEvent($exititem, "ExitFun")
TraySetState()
TraySetToolTip("常用托盘程序!")
While 1
Sleep(500)
WEnd
Exit
Func RunApp()
For $k = 1 To $varMenuKeyList[0][0]
If ($varMenuKeyList[$k][0] == @TRAY_ID) Then
ShellExecute($varMenuKeyList[$k][1])
EndIf
Next
EndFunc ;==>RunApp
Func RunFun()
RegWrite($sRegPath, @ScriptName, 'REG_SZ', '"' & @ScriptFullPath & '" /AUTO')
TrayItemSetState($Yes, $TRAY_CHECKED)
TrayItemSetState($No, $TRAY_UNCHECKED)
EndFunc ;==>RunFun
Func NoRunFun()
RegDelete($sRegPath, @ScriptName)
TrayItemSetState($Yes, $TRAY_UNCHECKED)
TrayItemSetState($No, $TRAY_CHECKED)
EndFunc ;==>RunFun
Func ExitFun()
Exit
EndFunc ;==>ExitFun
配置文件代码:;---------------------------------------------------------配置文件TrayMenu.ini------------------------------------
[TrayMenu]
1=常用网址
2=常用文件夹
[TrayItem]
1=百度一下;http://www.baidu.com
1=114啦;http://www.114la.com/kp.html
1=IT天空;http://sky123.org/
1=autoit中文网址;http://www.autoitx.com/index.php
2=文件夹测试;F:\文件夹\
;---------------------------------------------------------配置文件TrayMenu.ini------------------------------------
|