如何重建丢失的系统托盘图标(MSDN节选翻译)
2008-04-03 09:50
435 查看
Q:I have an application that adds an icon to the system tray. When Windows® Explorer goes down, many times it restarts automatically, but has lost its tray icons. Since my application is still running, do you know of a way I can detect that I need to re-add my tray icon to get my application UI back without requiring a reboot?
Jeff Multhaup
Boise, Idaho
Q:我有一个应用程序可以把图标加到系统托盘里。当explorer.exe崩溃重启以后,系统托盘里的图标也会丢失。因为我的应用程序仍在运行,所以有什么方法可以让我在需要的时候重新加入系统托盘图标而无需重新启动系统?
A: Sure, it's easy-provided you have Windows 98 or the Microsoft® Internet Explorer 4.0 desktop installed. Whenever Internet Explorer 4.0 starts the taskbar, it broadcasts a registered message TaskbarCreated to all top-level parent windows. This is your cue to recreate the icons. If you're using MFC, all you have to do is define a global variable to hold the registered message and implement an ON_REGISTERED_MESSAGE handler for it.
A:有的,在安装了Windows98或者Microsoft® Internet Explorer 4.0的系统上很容易办到。当IE4.0启动任务栏,它会向所有注册了“TaskBarCreated”消息的顶级窗口进行广播,用来提醒你重建图标。如果你使用MFC,你要做的就是定义一个全局变量保存该注册消息并在ON_REGISTERED_MESSAGE中注册一个消息处理函数。
The handler itself should reinstall whatever icons you need.
What could be easier? You should implement InstallIcons as a separate function instead of calling Shell_NotifyIcon directly from OnTaskBarCreated since presumably you will want to also call it when your app starts up.
还有比这更简单的吗?你应该把InstallIcons作为一个独立的函数而不是在OnTaskBarCreated里直接调用Shell_NotifyIcon。
Jeff Multhaup
Boise, Idaho
Q:我有一个应用程序可以把图标加到系统托盘里。当explorer.exe崩溃重启以后,系统托盘里的图标也会丢失。因为我的应用程序仍在运行,所以有什么方法可以让我在需要的时候重新加入系统托盘图标而无需重新启动系统?
A: Sure, it's easy-provided you have Windows 98 or the Microsoft® Internet Explorer 4.0 desktop installed. Whenever Internet Explorer 4.0 starts the taskbar, it broadcasts a registered message TaskbarCreated to all top-level parent windows. This is your cue to recreate the icons. If you're using MFC, all you have to do is define a global variable to hold the registered message and implement an ON_REGISTERED_MESSAGE handler for it.
A:有的,在安装了Windows98或者Microsoft® Internet Explorer 4.0的系统上很容易办到。当IE4.0启动任务栏,它会向所有注册了“TaskBarCreated”消息的顶级窗口进行广播,用来提醒你重建图标。如果你使用MFC,你要做的就是定义一个全局变量保存该注册消息并在ON_REGISTERED_MESSAGE中注册一个消息处理函数。
[code]const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(_T("TaskbarCreated"));
[code]BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
[code] ON_REGISTERED_MESSAGE(WM_TASKBARCREATED,OnTaskBarCreated)
[code]END_MESSAGE_MAP(CMainFrame, CFrameWnd)
The handler itself should reinstall whatever icons you need.
[code]LRESULT CMainFrame::OnTaskBarCreated(WPARAM wp, LPARAM lp)
[code]{
[code] VERIFY(InstallIcons());
[code] return 0;
[code]}
[code]BOOL CMainFrame::InstallIcons()
[code]{
[code] NOTIFYICONDATA nid;
[code] //
[code] // stuff nid with args
[code] //
[code] return Shell_NotifyIcon(NIM_ADD, &nid);
[code]}
What could be easier? You should implement InstallIcons as a separate function instead of calling Shell_NotifyIcon directly from OnTaskBarCreated since presumably you will want to also call it when your app starts up.
还有比这更简单的吗?你应该把InstallIcons作为一个独立的函数而不是在OnTaskBarCreated里直接调用Shell_NotifyIcon。
相关文章推荐
- 如何清除系统托盘历史图标?
- Win8.1系统如何全部显示隐藏的托盘图标?
- 系统托盘图标丢失
- Ubuntu:如何显示系统托盘图标(systray)
- CentOS 7:如何显示系统托盘图标(systray)
- BCB如何将应用程序图标写到系统托盘中
- 解决Java程序的托盘图标在Windows任务栏重建后丢失的问题(使用SystemTray类创建托盘图标)
- 如何设置系统托盘图标
- Win10如何显示系统托盘所有图标
- 如何有效的让系统托盘下的图标消失
- [VB.NET]如何将图标放在系统托盘上
- 如何使用GTK让系统显示托盘图标
- 如何在系统托盘(panel)中显示应用程序图标和气球帮助信息(balloon tooltips)
- 如何把程序图标添加到系统托盘上
- Ubuntu:如何显示系统托盘图标(systray)
- 如何在系统托盘上动态图标的实现
- [C#]如何让窗口最小化到系统托盘(右下角的小图标)
- 如何刷新系统托盘图标
- 解决Java程序的托盘图标在Windows任务栏重建后丢失的问题(使用SystemTray类创建托盘图标)
- Ubuntu-Desktop-12.04 如何设置系统托盘图标