diff --git a/SpiceRunner/CTaskBarIcon.h b/SpiceRunner/CTaskBarIcon.h index 1ec57f5..dc08f24 100644 --- a/SpiceRunner/CTaskBarIcon.h +++ b/SpiceRunner/CTaskBarIcon.h @@ -24,22 +24,30 @@ class CTaskBarIcon wcscpy_s(m_Data.szTip, InitialName); m_Data.uCallbackMessage = m_Message; m_TaskBarMessage = RegisterWindowMessage(TEXT("TaskbarCreated")); + Log("TaskbarCreated message = %d", m_TaskBarMessage); } ~CTaskBarIcon() { } void Attach() { + Log("%s", __FUNCTION__); m_Data.hWnd = m_Parent.GetWindowHandle(); Op(NIM_ADD); Op(NIM_SETVERSION); } void Detach() { + Log("%s", __FUNCTION__); Op(NIM_DELETE); } void ProcessIconMessage(UINT message, WPARAM wParam, LPARAM lParam) { + if (message == WM_TIMER && !CheckIcon()) { + Detach(); + Attach(); + return; + } if (m_TaskBarMessage && message == m_TaskBarMessage) { Detach(); Attach(); @@ -76,14 +84,24 @@ class CTaskBarIcon UINT m_Message; UINT m_TaskBarMessage; bool m_IconActive = false; - void Op(UINT operation) + bool Op(UINT operation) { - Shell_NotifyIcon(operation, &m_Data); + bool b = Shell_NotifyIcon(operation, &m_Data); + if (!b) { + Log("%s: error on operation %d", __FUNCTION__, operation); + } + return b; } bool IsIconMessage(UINT msg) { return msg == m_Data.uCallbackMessage; } + bool CheckIcon() + { + bool b = Op(NIM_MODIFY); + Log("%s: result %d", __FUNCTION__, b); + return b; + } class BooleanHolder { public: diff --git a/SpiceRunner/SpiceRunnerDlg.cpp b/SpiceRunner/SpiceRunnerDlg.cpp index c6f02e3..2433bde 100644 --- a/SpiceRunner/SpiceRunnerDlg.cpp +++ b/SpiceRunner/SpiceRunnerDlg.cpp @@ -53,7 +53,10 @@ BOOL CSpiceRunnerDlg::OnInitDialog() m_Icon.Attach(); LoadServers(); - return TRUE; // return TRUE unless you set the focus to a control + + SetTimer(1, 10000, NULL); + + return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below