Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Al Hunt's profile on WallpaperFusion.com
An annoying "feature" of the Windows Taskbar (or Icon Tray - whatever it's called) is that it doesn't refresh itself if you kill tasks. An icon for the killed task will remain in the icon tray until you mouse over the tray or some other event causes it to refresh itself.

BFS.Application has features (THANK YOU!) that let you easily kill tasks.

I'd like to request a related scripted function that causes a Task Bar and/or Icon Bar refresh.

Here's a link to some C# sample code for what I have in mind, but don't have the skill to make in to my own DisplayFusion function:

https://stackoverflow.com/questions/8342614/refreshing-system-tray-icons-programmatically

Thanks for your consideration.
Apr 20, 2018  • #1
PabloMartinez's profile on WallpaperFusion.com
Using the solution you found on stackoverflow, I adapted it for use in DisplayFusion. Perhaps there are simpler and more elegant solutions, but it is quite working as a temporary, until the developers do not implement their own. :)

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 appId = BFS.Application.GetAppIDByWindow(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");
        
        BFS.Application.Kill(appId);
        if (notificationAreaHandle == IntPtr.Zero)
        {
            var notifyIconOverflowWindowHandle = BFS.Window.GetWindowByClass("NotifyIconOverflowWindow");
            var overflowNotificationAreaHandle = BFS.Window.GetChildWindowByClass(notifyIconOverflowWindowHandle, "ToolbarWindow32");
            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);
    }
}
Apr 21, 2018  • #2
Al Hunt's profile on WallpaperFusion.com
Quote:
Using the solution you found on stackoverflow, I adapted it for use in DisplayFusion. Perhaps there are simpler and more elegant solutions, but it is quite working as a temporary, until the developers do not implement their own. :)


Thanks so much for taking the time to do this, Pablo!

I did have to delete lines 19 and 25 (kill the calling app?) above for it to work for me, but it's exactly what I needed.
Apr 21, 2018 (modified Apr 23, 2018)  • #3
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Thanks Pablo! I've added this to the online Scripted Function repository :)
Apr 23, 2018  • #4
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(1)  Login to Vote(-)