启动时系统托盘图标不出现 [英] System Tray Icon not appearing on startup

查看:197
本文介绍了启动时系统托盘图标不出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在FormCreate事件处理程序中使用以下代码创建系统托盘图标。当我运行我的程序时,系统托盘图标似乎正常。

I use the following code in the FormCreate event handler to create a system tray icon. When I run my program the system tray icon appears fine.

我设置我的应用程序在Windows启动时自动启动。当我重新启动计算机,我的应用程序的进程已启动,但系统托盘图标不会出现。

I set my application be started automatically on windows start up. When I restart the computer my application's process is started but the system tray icon never appears.

我认为这可能与运行代码的时间有关,也许系统托盘尚未准备好填充。

I think it might be something to do with the timing of when the code is run, that perhaps the system tray isn't ready to be populated.

我的应用程序在启动时通过它的NSIS安装程序运行:
WriteRegStr HKLMSoftware\Microsoft\Windows\CurrentVersion\RunMyApp $ INSTDIR\ MyApp.exe

I get my app to run at start up via it's NSIS installer : WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "MyApp" "$INSTDIR\ MyApp.exe"

创建系统托盘图标的代码:

Code to create system tray icon :

with TrayIconData do
  begin
    cbSize := SizeOf(TrayIconData);
    Wnd := Handle;
    uID := 0;
    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
    uCallbackMessage := WM_ICONTRAY;
    hIcon := Application.Icon.Handle;
    StrPCopy(szTip, Application.Title);
  end;

  Shell_NotifyIcon(NIM_ADD, @TrayIconData);


推荐答案

您尝试在资源管理器之前创建图标完全开始您应该正确处理错误(向下滚动到处理Shell_NotifyIcon失败 )

You're attempting to create the icon before Explorer has fully started. You should handle errors gracefully (scroll down to "Handling Shell_NotifyIcon failure").

您还应该处理 TaskbarCreated通知 - 它可以让您在Explorer崩溃并重新启动后重新创建图标。

You should also handle the TaskbarCreated notification -- it enables you to recreate your icons after Explorer crashes and restarts.

这篇关于启动时系统托盘图标不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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