有错误欢迎指正
1.duilib
duilib 中重启资源管理器后在自己处理windows消息HandleMessage里(或者自定义消息里面)
接收到SPI_SETICONTITLEWRAP 消息 添加图标
LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
if(uMsg == SPI_SETICONTITLEWRAP)
//重新加载图标
2、mfc
以下转自https://blog.csdn.net/sp_daiyq/article/details/41833037
杀掉explorer进程后,windows taskbar也就没有了,托盘图标也就跟着消失了。当explorer进程重启,taskbar将会被创建,taskbar创建后会使用字符串“TaskbarCreated”注册一个消息,然后将这个消息广播到它的所有top-level windows。因此我们可以去注册并捕获这个消息,然后在消息处理函数中调用
Shell_NotifyIcon(NIM_ADD, &m_nid); 重新将托盘图标添加上
MSDN中的说明:
Taskbar Creation Notification
Microsoft® Internet Explorer 4.0 will notify applications that the taskbar has been created. When the taskbar is created, it will register a message with the "TaskbarCreated" string and then broadcast this message to all top-level windows. When your taskbar application receives this message, it should assume that any taskbar icons it added have been removed and add them again.
相关实现代码:
1、注册“TaskbarCreated”消息
- const UINT WM_TaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
2、添加消息处理函数和消息映射
- afx_msg void OnTaskBarRestart(WPARAM wParam, LPARAM lParam); // .h
- ON_REGISTERED_MESSAGE(WM_TaskbarRestart, OnTaskBarRestart) // .cpp
3、实现消息处理函数
- void CMainFrame::OnTaskBarRestart(WPARAM wParam, LPARAM lParam)
- {
- Shell_NotifyIcon(NIM_ADD, &m_nid);
- }