找回密码
 加入
搜索
查看: 5300|回复: 12

如何刷新托盘图标

  [复制链接]
发表于 2009-4-7 15:19:23 | 显示全部楼层 |阅读模式
在对托盘图标进行一番操作以后,会发现显示滞后现象,用鼠标指针点一下才有反应。故需要刷新一下托盘图标,。
请问如何做到,谢谢。

[ 本帖最后由 jiataifeng 于 2009-4-21 06:53 编辑 ]
发表于 2009-4-7 18:11:19 | 显示全部楼层
不明白哦·==
发表于 2009-4-7 18:40:30 | 显示全部楼层
#Include <Constants.au3>
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
GUICreate("")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN,"_TRAY")
TraySetOnEvent($TRAY_EVENT_SECONDARYDOWN,"_TRAY")
While 1
Sleep(100)
WEnd
Func _TRAY()
Select
case @TRAY_ID=$TRAY_EVENT_PRIMARYDOWN
;TraySetIcon()
Case @TRAY_ID=$TRAY_EVENT_SECONDARYDOWN
;TraySetIcon()
EndSelect
EndFunc
 楼主| 发表于 2009-4-13 13:15:23 | 显示全部楼层
可以这样理解:
删除某个进程后,该进程的托盘图标还存在与托盘处。此时需要鼠标点击一下,才会消失。现在需要的就是“刷新”一下,而不用去点击。
就像刷新桌面一样的道理呀。
晕,这都无法理解了。
不过还是谢谢回答啦
发表于 2009-4-13 22:09:37 | 显示全部楼层
_RefreshSystemTray()
http://www.autoitscript.com/forum/index.php?showtopic=7404

;=========# _RefreshSystemTray #=====================================================
;Function Name:    _RefreshSystemTray()
;Description:      Removes any dead icons from the notification area.
;Parameters:       $nDealy - IN/OPTIONAL - The delay to wait for the notification area to expand with Windows XP's "Hide Inactive Icons" feature (In milliseconds).
;Return Value(s):  Success - Returns 1
;                  Failure - Returns 0 and sets @error to:
;                        1 - Tray couldn't be found.
;                        2 - DllCall error.
;Autor(s):         Valik
;====================================================================================
Func _RefreshSystemTray($nDelay = 1000)
        Local $hWnd, $hControl, $posStart, $posWin, $posX, $posY, $error = 0

        ; Save Opt settings
        Local $oldChildMode = Opt("WinSearchChildren", 1)
        Local $oldMatchMode = Opt("WinTitleMatchMode", 4)

        Do   ; Pseudo loop
                $hWnd = WinGetHandle("[CLASS:Shell_TrayWnd]")
                If @error Then
                        $error = 1
                        ExitLoop
                EndIf

                $hControl = ControlGetHandle($hWnd, "", "Button2")

                ; We're on XP and the Hide Inactive Icons button is there, so expand it
                If $hControl <> "" AND ControlCommand($hWnd, "", $hControl, "IsVisible") Then
                        ControlClick($hWnd, "", $hControl)
                        Sleep($nDelay)
                EndIf

                $posStart = MouseGetPos()
                $posWin = WinGetPos($hWnd)

                $posY = $posWin[1]
                While $posY < $posWin[1] + $posWin[3]
                        $posX = $posWin[0]
                        While $posX < $posWin[0] + $posWin[2]
                                DllCall("user32.dll", "int", "SetCursorPos", "int", $posX, "int", $posY)
                                If @error Then
                                        $error = 2
                                        ExitLoop 3   ; Jump out of While/While/Do
                                EndIf
                                $posX += 8
                        WEnd
                        $posY += 8
                WEnd
                DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1])

                ; We're on XP so we need to hide the inactive icons again.
                If $hControl <> "" AND ControlCommand($hWnd, "", $hControl, "IsVisible") Then
                        ControlClick($hWnd, "", $hControl)
                EndIf
        Until 1

        ; Restore Opt settings
        Opt("WinSearchChildren", $oldChildMode)
        Opt("WinTitleMatchMode", $oldMatchMode)

        If $error Then
                Return SetError($error, 0, 0)
        Else
                Return 1
        EndIf
EndFunc   ;==>_RefreshSystemTray


[ 本帖最后由 sensel 于 2009-4-13 22:11 编辑 ]

评分

参与人数 1金钱 +5 贡献 +5 收起 理由
jiataifeng + 5 + 5

查看全部评分

发表于 2010-3-4 21:15:15 | 显示全部楼层
强人了,,,,,,,,
发表于 2010-3-5 03:03:21 | 显示全部楼层
貌似效果不是很好
发表于 2011-4-10 20:24:23 | 显示全部楼层
关注ing 有没更好的
发表于 2011-4-10 20:30:51 | 显示全部楼层
刷新环境变量试试看
发表于 2012-3-13 13:24:20 | 显示全部楼层
关注。。。。。。。。
发表于 2012-3-13 13:30:44 | 显示全部楼层
关注。。。。。。。。
发表于 2013-1-19 22:06:29 | 显示全部楼层
留点  回来写代码试试看
发表于 2015-10-23 01:06:09 | 显示全部楼层
做的挺漂亮的,
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 22:17 , Processed in 0.085991 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表