您可以向Windows资源管理器发送信号以刷新系统托盘图标吗? [英] Can you send a signal to Windows Explorer to make it refresh the systray icons?

查看:146
本文介绍了您可以向Windows资源管理器发送信号以刷新系统托盘图标吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经困扰了我很长一段时间而且非常烦人。

This problem has been afflicting me for quite a while and it's been really annoying.

每次我重启/重启后登录时,资源管理器都需要一些时间出现。
我已经采取了等待所有服务启动的步骤,然后我登录,但它没有任何区别。
结果总是一样的:即使应用程序已启动,某些图标也不会显示。

Every time I login after a reboot/power cycle the explorer takes some time to show up. I've taken the step of waiting for all the services to boot up and then I login, but it doesn't make any difference. The result is always the same: Some of the icons do not show up even if the applications have started.

我在代码上挖了一下这使得一个应用程序粘贴在那里的一个图标,但是有一个API调用可以执行,所以资源管理器重新读取所有图标信息?像无效或重绘或类似的东西?

I've dug a bit on the code that makes one application "stick" an icon in there, but is there an API call that one can perform so explorer re-reads all that icon info? Like invalidate or redraw or something of the sort?

显然,看起来乔恩是对的,这是不可能的它。

Apparently, it looks like Jon was right and it's not possible to do it.

我跟随Bob Dizzle和Mark Ransom代码构建了这个(Delphi代码):

I've followed Bob Dizzle and Mark Ransom code and build this (Delphi Code):

procedure Refresh;
var
  hSysTray: THandle;
begin
  hSysTray := GetSystrayHandle;
  SendMessage(hSysTray, WM_PAINT, 0, 0);
end;

function GetSystrayHandle: THandle;
var
  hTray, hNotify, hSysPager: THandle;
begin
  hTray := FindWindow('Shell_TrayWnd', '');
  if hTray = 0 then
  begin
    Result := hTray;
    exit;
  end;

  hNotify := FindWindowEx(hTray, 0, 'TrayNotifyWnd', '');
  if hNotify = 0 then
  begin
    Result := hNotify;
    exit;
  end;

  hSyspager := FindWindowEx(hNotify, 0, 'SysPager', '');
  if hSyspager = 0 then
  begin
    Result := hSyspager;
    exit;
  end;

  Result := FindWindowEx(hSysPager, 0, 'ToolbarWindow32', 'Notification Area');
end;

但无济于事。

我甚至尝试过使用

InvalidateRect()

但仍然没有显示。

还有其他任何建议吗?

推荐答案

看一下这篇博客文章:刷新TASKBAR通知区域。我正在使用此代码刷新系统托盘以摆脱孤立的图标,它的工作完美。
博客文章内容非常丰富,并对作者为发现他的解决方案所采取的步骤提供了很好的解释。

Take a look at this blog entry: REFRESHING THE TASKBAR NOTIFICATION AREA. I am using this code to refresh the system tray to get rid of orphaned icons and it works perfectly. The blog entry is very informative and gives a great explanation of the steps the author performed to discover his solution.

#define FW(x,y) FindWindowEx(x, NULL, y, L"")

void RefreshTaskbarNotificationArea()
{
    HWND hNotificationArea;
    RECT r;

    GetClientRect(
        hNotificationArea = FindWindowEx(
            FW(FW(FW(NULL, L"Shell_TrayWnd"), L"TrayNotifyWnd"), L"SysPager"),
            NULL,
            L"ToolbarWindow32",
            // L"Notification Area"), // Windows XP
            L"User Promoted Notification Area"), // Windows 7 and up
        &r);

    for (LONG x = 0; x < r.right; x += 5)
        for (LONG y = 0; y < r.bottom; y += 5)
            SendMessage(
                hNotificationArea,
                WM_MOUSEMOVE,
                0,
                (y << 16) + x);
}

这篇关于您可以向Windows资源管理器发送信号以刷新系统托盘图标吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆