Jump to content

SystemTray_Refresh


rasim
 Share

Recommended Posts

Hi!

Very often i see messages e.g. "I kill program from task manager, but icon of this program still showed in system tray. How can clear taskbar from icons of killed app.`s?" And i have written this script:

#include <WinAPI.au3>

$hTaskBar = _WinAPI_FindWindow("Shell_TrayWnd", "")
$hParent  = ControlGetHandle($hTaskBar, "", "TrayNotifyWnd1")
$hWnd     = ControlGetHandle($hParent, "", "ToolbarWindow321")

$WinRect  = _WinAPI_GetWindowRect($hWnd)

$aMousePos = MouseGetPos()

$Left  = DllStructGetData($WinRect, "Left")
$Right = DllStructGetData($WinRect, "Right")
$Top   = DllStructGetData($WinRect, "Top")

For $i = $Left To $Right
    MouseMove($i, $Top, 0)
Next

MouseMove($aMousePos[0], $aMousePos[1], 0)

:)

Link to comment
Share on other sites

  • 2 months later...
  • 16 years later...
; Refresh taskbar icons without killing explorer.exe
Func RefreshTaskbarIcons()
    ; Constants for the Windows message
    Local $HWND_BROADCAST = 0xFFFF
    Local $WM_SETTINGCHANGE = 0x001A

    ; Send a message to all windows to refresh taskbar icons
    DllCall("user32.dll", "int", "SendMessageTimeout", _
            "hwnd", $HWND_BROADCAST, _
            "uint", $WM_SETTINGCHANGE, _
            "wparam", 0, _
            "lparam", "str", "TrayIcons", _
            "uint", 2, _
            "uint", 1000, _
            "uint*", 0)
EndFunc

; Call the function to refresh taskbar icons
RefreshTaskbarIcons()

 

Edited by r2du-soft
Link to comment
Share on other sites

i tried it but couldn't get it to work
I'm doing something wrong?

#include <GUIConstantsEx.au3>

Local $aProcces[6] = [5]

;Run GUI_Example in separate process as example Window
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If $CmdLine[0] > 0 Then
    ExampleGUI($CmdLine[1])
    Exit
EndIf
For $i = 1 To $aProcces[0]
    $aProcces[$i] = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" GUI_Example' & $i)
    ConsoleWrite($i & ") $aProcces=" & $aProcces[$i] & @CRLF)
Next
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sleep(10000)
For $i = 1 To $aProcces[0]
    If ProcessExists($aProcces[$i]) Then ProcessClose($aProcces[$i])
Next

ExampleGUI("Main GUI")
$hMyGUI = WinWait("Main GUI")

;----------------------------------------------------------------------------------------
Func ExampleGUI($sTitle)
    Local $hGUI, $iMethod1, $iMethod2, $Result
    $hGUI = GUICreate($sTitle, 300, 200)
    If $sTitle = "Main GUI" Then
        $iMethod1 = GUICtrlCreateButton("Method1 ", 10, 10)
        $iMethod2 = GUICtrlCreateButton("Method2 ", 10, 40)
    EndIf
    GUISetState(@SW_SHOW)

    Local $iMsg
    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $iMethod1
                $Result = RefreshTaskbarIcons()
                ConsoleWrite('- $Result = ' & $Result & ' >Error code: ' & @error & @CRLF) ;### Debug Console

            Case $iMethod2
                ShellTrayRefresh()

        EndSwitch
    WEnd
EndFunc   ;==>ExampleGUI
;----------------------------------------------------------------------------------------

; Refresh taskbar icons without killing explorer.exe
Func RefreshTaskbarIcons()
    ; Constants for the Windows message
    Local $HWND_BROADCAST = 0xFFFF
    Local $WM_SETTINGCHANGE = 0x001A

    ; Send a message to all windows to refresh taskbar icons
    DllCall("user32.dll", "int", "SendMessageTimeout", _
            "hwnd", $HWND_BROADCAST, _
            "uint", $WM_SETTINGCHANGE, _
            "wparam", 0, _
            "lparam", "str", "TrayIcons", _
            "uint", 2, _
            "uint", 1000, _
            "uint*", 0)
EndFunc

;----------------------------------------------------------------------------------------
; Title...........: ShellTrayRefresh.au3
; Description.....: Refreshes ShellTray to remove leftover zombie icons
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/page/25/#comment-1529091
;----------------------------------------------------------------------------------------
Func ShellTrayRefresh()
    Local $aStartPos = MouseGetPos()
    Local $hTrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]")
    Local $hTlb = ControlGetHandle($hTrayWnd, "", "ToolbarWindow323")
    Local $hBtn = ControlGetHandle($hTrayWnd, "", "Button2")
    Local $aPos = ControlGetPos($hTrayWnd, "", $hBtn)
    Local $aTPos = ControlGetPos($hTrayWnd, "", $hTlb)
    For $i = ($aPos[0] - 1) + ($aPos[2] / 2) To $aPos[0] + $aPos[2] + $aTPos[2] Step $aPos[2]
        MouseMove($i, @DesktopHeight - 3, 1)
;~      ConsoleWrite("$i=" & $i & @CRLF)
;~      Sleep(10)
    Next
    MouseMove($aStartPos[0], $aStartPos[1], 1)
EndFunc   ;==>ShellTrayRefresh

 

and looking for a clue I found this
I didn't understand, But it looks a lot like that
https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_SendMessageTimeout.htm

 

I know that I know nothing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...