如何在 Windows 中*默认*始终显示程序托盘图标?

发布于 2024-07-20 12:31:09 字数 81 浏览 11 评论 0原文

如果程序在 Windows 7 中第一次执行,它会自动隐藏图标。 是否有任何清单设置或选项可以强制 Windows 7 默认情况下始终显示该图标?

If a program is executed for the first time in Windows 7, it automatically hides the icon. Is there any manifest setting or option to force Windows 7 to always show the icon by default?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔戏命师 2024-07-27 12:31:09

不久前,微软的 Kate Gregory 在 .NET Rocks 播客中表示,这是不可能的。

她说:“如果用户想要它(托盘图标),他/她会把它放在那里”。
这样做的原因是为了防止托盘区域混乱。

In .NET Rocks podcast, not long time ago, Kate Gregory from Microsoft was saying that it is impossible.

She said something like: "If user wants it (tray icon) he/she will put it there".
Reason for this is to prevent mess in the tray area.

丢了幸福的猪 2024-07-27 12:31:09

如果您确实想显示托盘图标,您可以弹出一个带有最少文本的气球,然后通过以下代码示例再次隐藏气球和它的阴影:

trayIcon.ShowBalloonTip(30000, "", ".", ToolTipIcon.None)

Dim balloonHandle As IntPtr = GetBalloonHwnd(balloonText) ' mainly: FindWindow("tooltips_class32", Nothing)

If (balloonHandle <> IntPtr.Zero) Then
  Dim sysShadowClassHwnd As IntPtr = FindWindow("SysShadow", Nothing)

  ' will hide balloon and leaving a small shadow artifact - just for this balloon
  PostMessage(balloonHandle, WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero)
  SetWindowPos(balloonHandle, IntPtr.Zero, 0, 0, 0, 0, SWP_HIDEWINDOW)

  If (sysShadowClassHwnd <> IntPtr.Zero) Then
    ' this will remove the small shadow artifact
    PostMessage(sysShadowClassHwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero)
  End If
End If

如果您重复此操作(例如每 30 秒),您的托盘图标将保留因为 Explorer.exe 认为有一个气球打开以向用户显示。 一些小问题 - 例如无法直接右键单击图标 - 仍然存在。

我确实习惯于显示我们公司软件的托盘图标,用户不打算在每次更新时手动执行此操作。 所以也许这会对某人有所帮助...:)

否则,我完全同意:这应该只在用户手中,而不是由应用程序控制。

If you really want to show your tray-icon, you can popup a balloon with minimal text and just afterwards hide the balloon and it's shadow again by following code-example:

trayIcon.ShowBalloonTip(30000, "", ".", ToolTipIcon.None)

Dim balloonHandle As IntPtr = GetBalloonHwnd(balloonText) ' mainly: FindWindow("tooltips_class32", Nothing)

If (balloonHandle <> IntPtr.Zero) Then
  Dim sysShadowClassHwnd As IntPtr = FindWindow("SysShadow", Nothing)

  ' will hide balloon and leaving a small shadow artifact - just for this balloon
  PostMessage(balloonHandle, WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero)
  SetWindowPos(balloonHandle, IntPtr.Zero, 0, 0, 0, 0, SWP_HIDEWINDOW)

  If (sysShadowClassHwnd <> IntPtr.Zero) Then
    ' this will remove the small shadow artifact
    PostMessage(sysShadowClassHwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero)
  End If
End If

if you repeat this (e.g. every 30 seconds), your trayicon will stay there because Explorer.exe thinks, there is a balloon open to display to the user. A few minor issues - such as no right-click directly on icon - are still there.

I really used to show the tray icon for our company-software where the user are not intended to do this manually and for each update. So maybe this will help someone... :)

Otherwise, I totally agree: This should be only in hands of the user, not controlled by the application.

坚持沉默 2024-07-27 12:31:09

这当然不是“不可能”。 有一个未记录的 COM 接口 ITrayNotify,用于检索托盘图标并更改其可见性,由 Explorer 本身使用。 完整的 C++ 源代码在这里: http://thread0.me/tag/windows/

当然,使用非官方 API 有风险,Windows 8 对此 API 进行了重大更改,这意味着您必须对 XP 使用 2 种不同的定义 - Win7 和 Win8 - Win10。 不过,嘿,即使 Chrome 也使用此功能技巧。 只要确保正确处理故障即可。

It's certainly not "impossible". There is an undocumented COM interface ITrayNotify for retrieving tray icons and changing their visibility, used by Explorer itself. Full C++ source here: http://thread0.me/tag/windows/

Of course, using an unofficial API is risky and Windows 8 has intoduced breaking changes to this API, which means you have to use 2 different definitions for XP - Win7 and Win8 - Win10. But hey, even Chrome uses this trick. Just be sure to handle failures properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文