bool CXTPTrayIcon::HideIcon()
{
	if (m_bRemoved || m_bHidden)
	{
		return true;
	}

	if (IsShellVersion5())
	{
		m_niData.uFlags = NIF_STATE;
		m_niData.dwState = NIS_HIDDEN;
		m_niData.dwStateMask = NIS_HIDDEN;

		if (!ShellNotify(NIM_MODIFY))
		{
			m_bHidden = false;
		}
		else
		{
			m_bHidden = true;
		}

		return m_bHidden;
	}

	return RemoveIcon();
}
Beispiel #2
0
void CShellIconHelper<T>::DestroyShell ()
{
    ShellNotify (NIM_DELETE); // Remove the icon
    if (m_hWnd != NULL)
    {
        // Get rid of the hidden window
        DestroyWindow();
    }
}
bool CXTPTrayIcon::ShowBalloonTip(LPCTSTR lpszInfo, LPCTSTR lpszInfoTitle/*= NULL*/, DWORD dwInfoFlags/*= NIIF_NONE*/, UINT uTimeout/*= 10*/)
{
	bool bResult = false;

	if (IsShellVersion5() && lpszInfo)
	{
		// The balloon tooltip text can be up to 255 chars long.
		ASSERT(AfxIsValidString(lpszInfo));
		ASSERT(lstrlen(lpszInfo) < 256);

		// The balloon title text can be up to 63 chars long.
		if (lpszInfoTitle)
		{
			ASSERT(AfxIsValidString(lpszInfoTitle));
			ASSERT(lstrlen(lpszInfoTitle) < 64);
		}

		// dwInfoFlags must be valid.
		ASSERT(NIIF_NONE == dwInfoFlags ||
				NIIF_INFO == dwInfoFlags ||
				NIIF_WARNING == dwInfoFlags ||
				NIIF_ERROR == dwInfoFlags);

		// The timeout must be between 10 and 30 seconds.
		ASSERT(uTimeout >= 10 && uTimeout <= 30);

		m_niData.uFlags |= NIF_INFO;

		STRNCPY_S(m_niData.szInfo, _countof(m_niData.szInfo), lpszInfo, 255);

		if (lpszInfoTitle)
		{
			STRNCPY_S(m_niData.szInfoTitle, _countof(m_niData.szInfoTitle), lpszInfoTitle, 63);
		}
		else
		{
			m_niData.szInfoTitle[0] = _T('\0');
		}

		m_niData.uTimeout = (uTimeout * 1000); // convert time to millisecs
		m_niData.dwInfoFlags = dwInfoFlags;

		if (ShellNotify(NIM_MODIFY))
		{
			bResult = true;
		}

		// Zero out the balloon text string so that later operations won't redisplay
		// the balloon.
		m_niData.szInfo[0] = _T('\0');
	}

	return bResult;
}
void CXTPTrayIcon::InstallIconPending()
{
	// Is the icon display pending, and it's not been set as "hidden"?
	if (m_bRemoved || m_bHidden)
	{
		return;
	}

	// Reset the flags to what was used at creation
	m_niData.uFlags = m_uFlags;

	// Try and recreate the icon
	m_bShowPending = (ShellNotify(NIM_ADD) == FALSE);
}
bool CXTPTrayIcon::SetCallbackMessage(UINT uNewCallbackMessage)
{
	// Make sure we avoid conflict with other messages
	ASSERT(m_niData.uCallbackMessage >= WM_APP);

	m_niData.uCallbackMessage = uNewCallbackMessage;
	m_niData.uFlags = NIF_MESSAGE;

	if (!ShellNotify(NIM_MODIFY))
	{
		return false;
	}

	return true;
}
Beispiel #6
0
HRESULT CShellIconHelper<T>::CreateShell ()
{
    RECT rect;
    rect.left = rect.right = rect.top = rect.bottom = 0;

    // Create a hidden window (using CWindowImpl)
    HWND hWnd = Create (NULL, rect, "ShellIconHiddenWindow", WS_POPUP);

    if (hWnd != 0) // Was created?
    {
        // Add the icon into the shell
        ShellNotify (NIM_ADD);
        return S_OK;
    }
    else return HRESULT_FROM_WIN32 (GetLastError());
}
bool CXTPTrayIcon::AddIcon()
{
	if (!m_bRemoved)
	{
		RemoveIcon();
	}

	m_niData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
	if (!ShellNotify(NIM_ADD))
	{
		m_bShowPending = true;
		return false;
	}

	m_bRemoved = m_bHidden = false;

	return true;
}
bool CXTPTrayIcon::RemoveIcon()
{
	m_bShowPending = false;

	if (m_bRemoved)
	{
		return true;
	}

	m_niData.uFlags = 0;
	if (!ShellNotify(NIM_DELETE))
	{
		return false;
	}

	m_bRemoved = m_bHidden = true;

	return true;
}
bool CXTPTrayIcon::SetShellTooltip(LPCTSTR lpszTipText)
{
	ASSERT(AfxIsValidString(lpszTipText));
	ASSERT(_tcslen(lpszTipText) < m_iMaxTipSize);

	m_niData.uFlags = NIF_TIP;
	STRNCPY_S(m_niData.szTip, _countof(m_niData.szTip), lpszTipText, m_iMaxTipSize-1);

	if (m_bHidden)
	{
		return true;
	}

	if (!ShellNotify(NIM_MODIFY))
	{
		return false;
	}

	return true;
}
bool CXTPTrayIcon::SetNotificationWnd(CWnd* pWndNotify)
{
	ASSERT_VALID(pWndNotify);

	// Make sure Notification window is valid
	if (!pWndNotify || !::IsWindow(pWndNotify->GetSafeHwnd()))
	{
		return false;
	}

	// assign values
	m_niData.hWnd = pWndNotify->GetSafeHwnd();
	m_niData.uFlags = 0;

	if (!ShellNotify(NIM_MODIFY))
	{
		return false;
	}

	return true;
}
bool CXTPTrayIcon::ShowIcon()
{
	if (m_bRemoved)
		return AddIcon();

	if (!m_bHidden)
		return TRUE;

	if (IsShellVersion5())
	{
		m_niData.uFlags = NIF_STATE;
		m_niData.dwState = 0;
		m_niData.dwStateMask = NIS_HIDDEN;

		if (!ShellNotify(NIM_MODIFY))
			return false;

		m_bRemoved = m_bHidden = false;
		return true;
	}

	return AddIcon();
}
bool CXTPTrayIcon::SetIcon(HICON hIcon)
{
	// check to see if this icon was already set.
	if (m_niData.hIcon == hIcon)
	{
		return true;
	}

	m_niData.uFlags = NIF_ICON;
	m_niData.hIcon = hIcon;

	if (m_bHidden)
	{
		return true;
	}

	if (!ShellNotify(NIM_MODIFY))
	{
		return false;
	}

	return true;
}
LRESULT CXTPTrayIcon::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
	// Return quickly if its not for this tray icon
	if (wParam != m_niData.uID)
	{
		return 0L;
	}

	if (m_hWndNotify == NULL)
	{
		return 0L;
	}

	// Check to see if our notification window has already handled this
	// message, if so then return success.
	if (::SendMessage(m_hWndNotify, TIN_XTP_TRAYICON, wParam, lParam))
	{
		return 1;
	}

	switch (LOWORD(lParam))
	{

	// Sent when the balloon is shown (balloons are queued).
	case NIN_BALLOONSHOW:
		break;

	// Sent when the balloon disappears-for example, when the
	// icon is deleted. This message is not sent if the balloon
	// is dismissed because of a timeout or a mouse click.
	case NIN_BALLOONHIDE:
		break;

	// Sent when the balloon is dismissed because of a timeout.
	case NIN_BALLOONTIMEOUT:
		break;

	// Sent when the balloon is dismissed because of a mouse click.
	case NIN_BALLOONUSERCLICK:
		break;

	// The version 5.0 Shell sends the associated application a NIN_SELECT message
	// if a user selects a notify icon with the mouse and activates it with the ENTER key

	case NIN_SELECT:
		// intentional fall thru...

	// The version 5.0 Shell sends the associated application a NIN_KEYSELECT message
	// if a user selects a notify icon with the keyboard and activates it with the space bar or ENTER key

	case NIN_KEYSELECT:
		// intentional fall thru...

	// The version 5.0 Shell sends the associated application a WM_CONTEXTMENU
	// If a user requests a notify icon's shortcut menu with the keyboard
	case WM_CONTEXTMENU:
		// intentional fall thru...

	case WM_RBUTTONUP:
		{
			CMenu menu;
			if (!menu.LoadMenu(m_niData.uID))
			{
				return 0;
			}

			CMenu* pSubMenu = menu.GetSubMenu(0);
			if (pSubMenu == NULL)
			{
				return 0;
			}

			// Make chosen menu item the default (bold font)
			::SetMenuDefaultItem(pSubMenu->m_hMenu,
				m_uDefMenuItemID, m_bDefMenuItemByPos);

			// Display the menu at the current mouse location. There's a "bug"
			// (Microsoft calls it a feature) in Windows 95 that requires calling
			// SetForegroundWindow. To find out more, search for Q135788 in MSDN.
			//
			CPoint pos;
			GetCursorPos(&pos);
			::SetForegroundWindow(m_hWndNotify);

			::TrackPopupMenu(pSubMenu->m_hMenu, 0, pos.x, pos.y,
				0, m_hWndNotify, NULL);

			::PostMessage(m_hWndNotify, WM_NULL, 0, 0);

			menu.DestroyMenu();

			ShellNotify(NIM_SETFOCUS);
		}
		break;

	case WM_LBUTTONDBLCLK:
		{
			// double click received, the default action is to execute default menu item
			::SetForegroundWindow(m_hWndNotify);

			UINT uItem;
			if (m_bDefMenuItemByPos)
			{
				CMenu menu;
				if (!menu.LoadMenu(m_niData.uID))
				{
					return 0;
				}

				CMenu* pSubMenu = menu.GetSubMenu(0);
				if (pSubMenu == NULL)
				{
					return 0;
				}

				uItem = pSubMenu->GetMenuItemID(m_uDefMenuItemID);

				menu.DestroyMenu();
			}
			else
			{
				uItem = m_uDefMenuItemID;
			}

			::SendMessage(m_hWndNotify, WM_COMMAND, uItem, 0);
		}
	}

	return 1;
}
Beispiel #14
0
void CShellIconHelper<T>::SetShellIcon (WORD IconResource)
{
    // Save this icon resource for when we update
    m_CurrentIconResource = IconResource;
    ShellNotify (NIM_MODIFY);
}
Beispiel #15
0
void CShellIconHelper<T>::SetShellTipText (const char *TipText)
{
    // Save this text for when we update
    strncpy(m_CurrentText, TipText, sizeof(m_CurrentText));
    ShellNotify (NIM_MODIFY);
}