예제 #1
0
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 ( !Shell_NotifyIcon(NIM_SETVERSION, &notifyData) )
    {
        wxLogLastError(wxT("Shell_NotifyIcon(NIM_SETVERSION)"));
    }

    // do show the balloon now
    notifyData = NotifyIconData(hwnd);
    notifyData.uFlags |= NIF_INFO;
    notifyData.uTimeout = msec;
    wxStrlcpy(notifyData.szInfo, text.t_str(), WXSIZEOF(notifyData.szInfo));
    wxStrlcpy(notifyData.szInfoTitle, title.t_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 = Shell_NotifyIcon(NIM_MODIFY, &notifyData) != 0;
    if ( !ok )
    {
        wxLogLastError(wxT("Shell_NotifyIcon(NIM_MODIFY)"));
    }

    return ok;
}
예제 #2
0
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, &notifyData) )
	{
		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, &notifyData) != 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
}