本帖最后由 owkj 于 2009-5-4 20:50 编辑
问题:用autoir3结束了一个进程,这个进程在任务栏有图标(比如privoxy.exe),用autoir3结束了进程后,其托盘图标还在,必须把光标移到托盘图标 上才会消失,怎么让au3结束这个进程后刷新任务栏图标,使被结束的进程的图标消失?
在http://www.autoitx.com论坛找了些资料,最后成功解决了本问题。
方案一:使用_RefreshSystemTray函数,查看6楼帖子http://www.autoitx.com/forum.php?mod=viewthread&tid=1480
例子:sshr.au3
#NoTrayIcon
If ProcessExists ( "myentunnel.exe" ) Or ProcessExists ( "privoxy.exe" ) Then
ProcessClose("myentunnel.exe")
ProcessClose("privoxy.exe")
ProcessClose("Plink.exe")
_RefreshSystemTray()
_RefreshSystemTray()
Else
ShellExecute (@ScriptDir & "\"&"privoxy.exe" , "config.txt" , @ScriptDir , "" ,@SW_HIDE)
Run("myentunnel.exe")
EndIf
Func _RefreshSystemTray($nDelay = 1000)
Local $oldMatchMode = Opt("WinTitleMatchMode", 4)
Local $oldChildMode = Opt("WinSearchChildren", 1)
Local $error = 0
Do
Local $hWnd = WinGetHandle("classname=TrayNotifyWnd")
If @error Then
$error = 1
ExitLoop
EndIf
Local $hControl = ControlGetHandle($hWnd, "", "Button1")
If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
ControlClick($hWnd, "", $hControl)
Sleep($nDelay)
EndIf
Local $posStart = MouseGetPos()
Local $posWin = WinGetPos($hWnd)
Local $y = $posWin[1]
While $y < $posWin[3] + $posWin[1]
Local $x = $posWin[0]
While $x < $posWin[2] + $posWin[0]
DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y)
If @error Then
$error = 2
ExitLoop 3;
EndIf
$x += 8
WEnd
$y += 8
WEnd
DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1])
If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
ControlClick($hWnd, "", $hControl)
EndIf
Until 1
Opt("WinTitleMatchMode", $oldMatchMode)
Opt("WinSearchChildren", $oldChildMode)
SetError($error)
EndFunc
缺点:刷新托盘图标时会看到鼠标移动到了托盘图标上,虽然只是一瞬间的事。
还有一个问题是,某次我将桌面主题换为windows经典后,上面的脚本却只能将结束的两个进程的其中一个的托盘图标隐藏,很怪异,刚刚又试了一下,却正常了。
方案二: 使用SysTray_UDF.au3,在结束进程前,先用_SysTrayIconVisible函数隐藏它的托盘图标,然后再结束它的进程。看起来就象是将托盘图标刷新了一下。本人感觉这个方法更好一些。
例子:ssh.au3
;自动调用ssh代理,第一次运行自动调用myentunnel和privoxy,再运行一次可结束myentunnel和privoxy,并隐藏myentunnel和privoxy的图标
#include "SysTray_UDF.au3"
If ProcessExists ( "myentunnel.exe" ) Or ProcessExists ( "privoxy.exe" ) Then
_SysTrayIconVisible(1, _SysTrayIconIndex("privoxy.exe"));隐藏privoxy的托盘图标
_SysTrayIconVisible(1, _SysTrayIconIndex("myentunnel.exe"));隐藏myentunnel的托盘图标
ProcessClose("myentunnel.exe")
ProcessClose("privoxy.exe")
ProcessClose("Plink.exe")
TraySetState (1);必须的,否则隐藏myentunnel和privoxy的图标后托盘处会有空白
Else
ShellExecute (@ScriptDir & "\"&"privoxy.exe" , ".\config.txt" , @ScriptDir , "" ,@SW_HIDE)
Run("myentunnel.exe")
EndIf
下载地址(本文中两个例子及其所用到的东西)
http://www.ucomo.com/space/FileD ... 579&DOMAIN=OWKJ |