diff --git a/client/win/wingui_mainwindow.cpp b/client/win/wingui_mainwindow.cpp index fa56ee1949..4a74de8b7f 100755 --- a/client/win/wingui_mainwindow.cpp +++ b/client/win/wingui_mainwindow.cpp @@ -202,6 +202,10 @@ void CMainWindow::UpdateGUI(CLIENT_STATE* pcs) CString strBuf; int i; + // If we failed to set the taskbar icon before, keep trying! + if (m_nDesiredIconState != m_nIconState) + SetStatusIcon(m_nDesiredIconState); + // display projects m_ProjectListCtrl.SetRedraw(FALSE); float totalres = 0; @@ -537,14 +541,17 @@ void CMainWindow::ShowTab(int nTab) // arguments: dwMessage: hide or show the icon // returns: void // function: controls the status icon in the taskbar -void CMainWindow::SetStatusIcon(DWORD dwMessage) +bool CMainWindow::SetStatusIcon(DWORD dwMessage) { + BOOL success = false; + NOTIFYICONDATA icon_data; + if(dwMessage != ICON_OFF && dwMessage != ICON_NORMAL && dwMessage != ICON_HIGHLIGHT) { - return; + return false; } // if icon is in that state already, there is nothing to do - if(dwMessage == m_nIconState) return; - NOTIFYICONDATA icon_data; + if(dwMessage == m_nIconState) return true; + m_nDesiredIconState = dwMessage; memset( &icon_data, 0, sizeof(NOTIFYICONDATA) ); icon_data.cbSize = sizeof(NOTIFYICONDATA); icon_data.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; @@ -554,23 +561,27 @@ void CMainWindow::SetStatusIcon(DWORD dwMessage) icon_data.uCallbackMessage = STATUS_ICON_ID; if(dwMessage == ICON_OFF) { icon_data.hIcon = NULL; - Shell_NotifyIcon(NIM_DELETE, &icon_data); + success = Shell_NotifyIcon(NIM_DELETE, &icon_data); } else if(dwMessage == ICON_NORMAL) { icon_data.hIcon = g_myApp.LoadIcon(IDI_ICON); if(m_nIconState == ICON_OFF) { - Shell_NotifyIcon(NIM_ADD, &icon_data); + success = Shell_NotifyIcon(NIM_ADD, &icon_data); } else { - Shell_NotifyIcon(NIM_MODIFY, &icon_data); + success = Shell_NotifyIcon(NIM_MODIFY, &icon_data); } } else if(dwMessage == ICON_HIGHLIGHT) { icon_data.hIcon = g_myApp.LoadIcon(IDI_ICONHIGHLIGHT); if(m_nIconState == ICON_OFF) { - Shell_NotifyIcon(NIM_ADD, &icon_data); + success = Shell_NotifyIcon(NIM_ADD, &icon_data); } else { - Shell_NotifyIcon(NIM_MODIFY, &icon_data); + success = Shell_NotifyIcon(NIM_MODIFY, &icon_data); } } + if (!success) return false; + m_nIconState = dwMessage; + + return true; } ////////// diff --git a/client/win/wingui_mainwindow.h b/client/win/wingui_mainwindow.h index cf6e9ac2c8..6badf38643 100755 --- a/client/win/wingui_mainwindow.h +++ b/client/win/wingui_mainwindow.h @@ -106,6 +106,7 @@ protected: CBitmap m_TabBMP[MAX_TABS]; // bitmaps for tab image list HINSTANCE m_hIdleDll; // handle to dll for user idle int m_nIconState; // state of the status icon + int m_nDesiredIconState; // desired state of the status icon BOOL m_bMessage; // does the user have a new message? BOOL m_bRequest; // does the user have a net connection request? int m_nContextItem; // item selected for context menu @@ -117,7 +118,7 @@ protected: COLORREF GetPieColor(int); void CheckIdle(); void ShowTab(int); - void SetStatusIcon(DWORD); + bool SetStatusIcon(DWORD); void SaveListControls(); void LoadListControls(); void SaveUserSettings();