bool wxTaskBarIcon::ShowBalloon(const wxString& title, const wxString& text, unsigned msec, int flags) { wxCHECK_MSG( m_iconAdded, false, wxT("can't be used before the icon is created") ); const HWND hwnd = GetHwndOf(m_win); // we need to enable version 5.0 behaviour to receive notifications about // the balloon disappearance NotifyIconData notifyData(hwnd); notifyData.uFlags = 0; notifyData.uVersion = 3 /* NOTIFYICON_VERSION for Windows 2000/XP */; if ( !wxShellNotifyIcon(NIM_SETVERSION, ¬ifyData) ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_SETVERSION)")); } // do show the balloon now notifyData = NotifyIconData(hwnd); notifyData.uFlags |= NIF_INFO; notifyData.uTimeout = msec; wxStrlcpy(notifyData.szInfo, text.wx_str(), WXSIZEOF(notifyData.szInfo)); wxStrlcpy(notifyData.szInfoTitle, title.wx_str(), WXSIZEOF(notifyData.szInfoTitle)); if ( flags & wxICON_INFORMATION ) notifyData.dwInfoFlags |= NIIF_INFO; else if ( flags & wxICON_WARNING ) notifyData.dwInfoFlags |= NIIF_WARNING; else if ( flags & wxICON_ERROR ) notifyData.dwInfoFlags |= NIIF_ERROR; bool ok = wxShellNotifyIcon(NIM_MODIFY, ¬ifyData) != 0; if ( !ok ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_MODIFY)")); } return ok; }
bool wxTaskBarIcon::RemoveIcon() { if (!m_iconAdded) return false; m_iconAdded = false; NotifyIconData notifyData(GetHwndOf(m_win)); bool ok = wxShellNotifyIcon(NIM_DELETE, ¬ifyData) != 0; if ( !ok ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_DELETE)")); } return ok; }
// Operations bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) { // NB: we have to create the window lazily because of backward compatibility, // old applications may create a wxTaskBarIcon instance before wxApp // is initialized (as samples/taskbar used to do) if (!m_win) { m_win = new wxTaskBarIconWindow(this); } m_icon = icon; m_strTooltip = tooltip; NotifyIconData notifyData(GetHwndOf(m_win)); if (icon.Ok()) { notifyData.uFlags |= NIF_ICON; notifyData.hIcon = GetHiconOf(icon); } // set NIF_TIP even for an empty tooltip: otherwise it would be impossible // to remove an existing tooltip using this function notifyData.uFlags |= NIF_TIP; if ( !tooltip.empty() ) { wxStrlcpy(notifyData.szTip, tooltip.wx_str(), WXSIZEOF(notifyData.szTip)); } bool ok = wxShellNotifyIcon(m_iconAdded ? NIM_MODIFY : NIM_ADD, ¬ifyData) != 0; if ( !ok ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_MODIFY/ADD)")); } if ( !m_iconAdded && ok ) m_iconAdded = true; return ok; }
// Operations bool gcTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) { #ifdef WIN32 m_icon = icon; m_strTooltip = tooltip; NotifyIconData notifyData(GetHwndOf(m_win)); if (icon.Ok()) { notifyData.uFlags |= NIF_ICON; notifyData.hIcon = GetHiconOf(icon); } // set NIF_TIP even for an empty tooltip: otherwise it would be impossible // to remove an existing tooltip using this function notifyData.uFlags |= NIF_TIP; if ( !tooltip.empty() ) { wxStrlcpy(notifyData.szTip, tooltip.wx_str(), WXSIZEOF(notifyData.szTip)); } bool ok = wxShellNotifyIcon(m_iconAdded ? NIM_MODIFY : NIM_ADD, ¬ifyData) != 0; if ( !ok ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_MODIFY/ADD)")); } if ( !m_iconAdded && ok ) m_iconAdded = true; return ok; #else return wxTaskBarIcon::SetIcon(icon, tooltip); #endif }
bool gcTaskBarIcon::ShowBalloon(const wxString& title, const wxString& text, unsigned msec, int flags) { #if defined(WIN32) wxCHECK_MSG( m_iconAdded, false, _T("can't be used before the icon is created") ); const HWND hwnd = GetHwndOf(m_win); // we need to enable version 5.0 behaviour to receive notifications about // the balloon disappearance NotifyIconData notifyData(hwnd); notifyData.uFlags = 0; notifyData.uVersion = 3 /* NOTIFYICON_VERSION for Windows XP */; if ( !wxShellNotifyIcon(NIM_SETVERSION, ¬ifyData) ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_SETVERSION)")); } // do show the balloon now notifyData = NotifyIconData(hwnd); notifyData.uFlags |= NIF_INFO; notifyData.uTimeout = msec; wxStrlcpy(notifyData.szInfo, text.wx_str(), WXSIZEOF(notifyData.szInfo)); wxStrlcpy(notifyData.szInfoTitle, title.wx_str(), WXSIZEOF(notifyData.szInfoTitle)); if ( flags & wxICON_INFORMATION ) notifyData.dwInfoFlags |= NIIF_INFO; else if ( flags & wxICON_WARNING ) notifyData.dwInfoFlags |= NIIF_WARNING; else if ( flags & wxICON_ERROR ) notifyData.dwInfoFlags |= NIIF_ERROR; bool ok = wxShellNotifyIcon(NIM_MODIFY, ¬ifyData) != 0; if ( !ok ) { wxLogLastError(wxT("wxShellNotifyIcon(NIM_MODIFY)")); } return ok; #elif defined(NIX) const char* icon = NULL; if ( flags & wxICON_INFORMATION ) icon = "dialog-information"; else if ( flags & wxICON_WARNING ) icon = "dialog-warning"; else if ( flags & wxICON_ERROR ) icon = "dialog-error"; NotifyNotification* notification = notify_notification_new( title.c_str(), text.c_str(), icon); notify_notification_show(notification, NULL); return true; #else return false; #endif }