CTrayNotifyIcon

Welcome to CTrayNotifyIcon, A freeware MFC class to encapsulate the tray notification API in 95,98 and NT 4.

 

Features
History
API Reference
Contacting the Author

 

 

 

Features

 

 

 

History

V1.3 (22 July 1998)

v1.2 (23 June 1998)

v1.1 (25 November 1997)

v1.0 (14 May 1997)

 

 

 

API Reference

Instantiate a CTrayNotifyIcon where it will be around for the lifetime of your icon. The sample program does this in the mainframe as the icon will be available for the lifetime of the application. In the sample program this is done in the mainframe class. The API consists of the the following public functions of the class CTrayNotifyIcon

 

CTrayNotifyIcon::CTrayNotifyIcon
CTrayNotifyIcon::~CTrayNotifyIcon
CTrayNotifyIcon::Create
CTrayNotifyIcon::SetTooltipText
CTrayNotifyIcon::GetTooltipText
CTrayNotifyIcon::SetIcon
CTrayNotifyIcon::SetStandardIcon
CTrayNotifyIcon::GetIcon
CTrayNotifyIcon::UsingAnimatedIcon
CTrayNotifyIcon::SetNotificationWnd
CTrayNotifyIcon::GetNotificationWnd
CTrayNotifyIcon::HideIcon
CTrayNotifyIcon::ShowIcon
CTrayNotifyIcon::RemoveIcon
CTrayNotifyIcon::MoveToExtremeRight
CTrayNotifyIcon::OnTrayNotification
CTrayNotifyIcon::IsShowing
CTrayNotifyIcon::IsHidden

 

CTrayNotifyIcon::CTrayNotifyIcon

CTrayNotifyIcon::CTrayNotifyIcon();

Remarks

Standard constructor, just initialises all member variables to safe values.

 

CTrayNotifyIcon::~CTrayNotifyIcon

CTrayNotifyIcon::~CTrayNotifyIcon();

Remarks

Standard destructor. Internally this will call RemoveIcon to remove the icon from the UI.

 

CTrayNotifyIcon::Create

BOOL CTrayNotifyIcon::Create(CWnd* pNotifyWnd, UINT nID, LPCTSTR pszTooltipText, HICON hIcon, UINT nNotifyMessage);

BOOL CTrayNotifyIcon::Create(CWnd* pNotifyWnd, UINT uID, LPCTSTR pszTooltipText, HICON* phIcons, int nNumIcons, DWORD dwDelay, UINT nNotifyMessage);

Return Value

TRUE if the tray icon was successfully created otherwise FALSE.

Parameters

pNotifyWnd: The window to send notification messages to. This can be changed later by using the SetNotificationWnd method.

uID: An application defined value to associate with each tray icon. This allows you to display multiple icons from one app. CTrayNotifyIcon also overrides its meaning such that it is used as the menu resource id for the context menu.

pszTooltipText: Initial tooltip text to display. This can be changed later using the SetTooltipText method.

hIcon: The icon to display. This can be changed later using the SetIcon method.

nNotifyMessage: This is the notification message to use to inform the window about mouse messages. This should be defined as some WM_USER message and handled in the notification windows message map using the ON_MESSAGE macro. To see how to hook this up have a look at the mainfrm.cpp

phIcons: pointer to an array of icon handles to use to do the icon animation.

nNumIcons: The number of icons phIcons points to.

dwDelay: interval in milliseconds between icon animation frames.

Remarks

Creates a tray notification icon.

 

CTrayNotifyIcon::SetTooltipText

BOOL CTrayNotifyIcon::SetTooltipText(LPCTSTR pszTooltipText);

BOOL CTrayNotifyIcon::SetTooltipText(UINT nID);

Return Value

TRUE if the tooltip text was changed successfully otherwise FALSE

Parameters

pszTooltipText The text to set

nID A windows string resource ID of the text to set

Remarks

Sets the tooltip text associated with the tray icon

 

CTrayNotifyIcon::GetTooltipText

CString CTrayNotifyIcon::GetTooltipText() const

Return Value

The current tooltip text

 

CTrayNotifyIcon::SetIcon

BOOL SetIcon(HICON hIcon);

BOOL SetIcon(LPCTSTR lpIconName);

BOOL SetIcon(UINT nIDResource);

BOOL SetIcon(HICON* phIcons, int nNumIcons, DWORD dwDelay);

Return Value

TRUE if the icon was changed successfully otherwise FALSE

Parameters

hIcon handle to the icon to set

lpIconName a Windows Icon resource string of the icon to use

nIDResource a Windows Icon resource ID of the icon to use

phIcons: pointer to an array of icon handles to use to do the icon animation.

nNumIcons: The number of icons phIcons points to.

dwDelay: interval in milliseconds between icon animation frames.

Remarks

Sets the icon associated with the tray icon

 

CTrayNotifyIcon::SetStandardIcon

BOOL CTrayNotifyIcon::SetStandardIcon(LPCTSTR lpIconName);

BOOL CTrayNotifyIcon::SetStandardIcon(UINT nIDResource);

Parameters

lpIconName a Windows Icon resource string of the icon to use

nIDResource a Windows Icon resource ID of the icon to use

Remarks

Sets the icon associated with the tray icon using the standard icon identifiers.

To use one of the Windows predefined icons, the lpIconName parameter to one of the following values:

Value Description
IDI_APPLICATION Default application icon.
IDI_ASTERISK Same as IDI_INFORMATION.
IDI_ERROR Hand-shaped icon.
IDI_EXCLAMATION Same as IDI_WARNING.
IDI_HAND Same as IDI_ERROR.
IDI_INFORMATION Asterisk icon.
IDI_QUESTION Question mark icon.
IDI_WARNING Exclamation point icon.
IDI_WINLOGO Windows logo icon.

 

CTrayNotifyIcon::GetIcon

HICON CTrayNotifyIcon::GetIcon() const;

Return Value

Icon handle of the icon currently being displayed

 

CTrayNotifyIcon::UsingAnimatedIcon

BOOL UsingAnimatedIcon() const;

Return Value

TRUE if an animated icon is being show, FALSE if an ordinary static icon is being used.

 

CTrayNotifyIcon::SetNotificationWnd

BOOL CTrayNotifyIcon::SetNotificationWnd(CWnd* pNotifyWnd);

Return Value

TRUE if the notification window was successfully set otherwise FALSE

Parameters

pNotifyIcon The window which is to be the notification window associated with this tray icon

 

CTrayNotifyIcon::GetNotificationWnd

CWnd* GetNotificationWnd() const;

Return Value

The window which is the notification window associated with this tray icon

 

CTrayNotifyIcon::HideIcon

void CTrayNotifyIcon::HideIcon();

Remarks

Temporarily hides the tray notify icon

 

CTrayNotifyIcon::ShowIcon

void CTrayNotifyIcon::ShowIcon();

Remarks

Shows the icon if it had previously been hidden

 

CTrayNotifyIcon::RemoveIcon

void CTrayNotifyIcon::RemoveIcon();

Remarks

Removes the tray icon entirely and resets the class member variables. This is the corollary function of CTrayNotifyIcon::Create

 

CTrayNotifyIcon::MoveToExtremeRight

void MoveToExtremeRight();

Remarks

Moves the tray icon to the extreme right of the tray notification area. This is achieved by first hiding the icon followed by re showing it.

 

CTrayNotifyIcon::OnTrayNotification

virtual LRESULT CTrayNotifyIcon::OnTrayNotification(WPARAM uID, LPARAM lEvent);

Return Value

Standard result to return from the message handler

Parameters

uID the value you specified in the call to CTrayNotifyIcon::Create

lEvent is a mouse event (such as WM_LBUTTONDOWN).

Remarks

When your handler gets control, WPARAM is the ID you specified when you created the CTrayNotifyIcon. LPARAM is the mouse event (for example,WM_LBUTTONDOWN). You can do whatever you like when you get the notification. NOTTEST does nothing and delegates all the work to the default implementation in CTrayNotifyIcon This virtual (so you can override it) function implements the default UI behaviour as outlined in the "Windows Interface Guidelines for Software".

 

CTrayNotifyIcon::IsShowing

BOOL CTrayNotifyIcon::IsShowing() const;

Return Value

TRUE if the tray icon is currently been shown else FALSE

 

CTrayNotifyIcon::IsHidden

BOOL CTrayNotifyIcon::IsHidden();

Return Value

TRUE if the tray icon is currently hidden else FALSE

 

 

 

CONTACTING THE AUTHOR

PJ Naughter
Email: pjn@indigo.ie
Web: http://indigo.ie/~pjn
22 July 1998