Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Refresh Tray Icons

Description
This script will cause the tray icons on the taskbar to refresh (makes an icon for a terminated process go away).
Language
C#.net
Minimum Version
Created By
PabloMartinez
Contributors
-
Date Created
Apr 23, 2018
Date Last Modified
Jun 30, 2018

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
    [DllImport("user32.dll")]
    public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
    
	public static void Run(IntPtr windowHandle)
	{
		var sysTrayContainerHandle = BFS.Window.GetWindowByClass("Shell_TrayWnd");
		var sysTrayHandle = BFS.Window.GetChildWindowByClass(sysTrayContainerHandle, "TrayNotifyWnd");
		var sysPagerHandle = BFS.Window.GetChildWindowByClass(sysTrayHandle, "SysPager");
		var notificationAreaHandle = BFS.Window.GetChildWindowByClass(sysPagerHandle, "ToolbarWindow32");
		var notifyIconOverflowWindowHandle = BFS.Window.GetWindowByClass("NotifyIconOverflowWindow");
        var overflowNotificationAreaHandle = BFS.Window.GetChildWindowByClass(notifyIconOverflowWindowHandle, "ToolbarWindow32");
		
		if (notificationAreaHandle == IntPtr.Zero)
            RefreshTrayArea(overflowNotificationAreaHandle);
        
		RefreshTrayArea(notificationAreaHandle);
	}
	
	private static void RefreshTrayArea(IntPtr windowHandle)
	{
        const uint wmMousemove = 0x0200;
        var rect = BFS.Window.GetClientRect(windowHandle);
        
        for (var x = 0; x < rect.Right; x += 5)
            for (var y = 0; y < rect.Bottom; y += 5)
                SendMessage(windowHandle, wmMousemove, 0, (y << 16) + x);
	}
}