MFC task tray often disappearing

      Often find myself writing a program in the task tray will disappear for no reason, but the process still exists, the original Explorer abnormal when regenerate, the program needs to re-add the next task tray.

     When the restart process explorer, taskbar will be created, the taskbar will be used to create a string "TaskbarCreated" registration message, then the message is broadcast to all of its top-level windows. So we can go to register and capture the news, and then call Shell_NotifyIcon (NIM_ADD, & m_nid) in the message handler; on the tray icon will be added again.

 Defined WM_TaskbarRestart

  1 const UINT WM_TaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated")); 

1 ON_REGISTERED_MESSAGE(WM_TaskbarRestart, &CXXXDlg::OnTaskBarRestart)
2 
3 LRESULT CXXXDlg::OnTaskBarRestart(WPARAM wParam, LPARAM lParam)
4 {
5     Shell_NotifyIcon(NIM_ADD, &m_nId);
6 
7     return 0;
8 }

statement;

afx_msg LRESULT OnTaskBarRestart(WPARAM wParam, LPARAM lParam);

Guess you like

Origin www.cnblogs.com/ahcc08/p/10987893.html