Changes to the sample project:
CMainFrame::OnCreate()
CMainFrame - Added handlers for Tray menu items.
stdafx.h
SystemTray.cpp/h - I marked my changes/additions with "(md)".
SystemDrayDemo.cpp - I let the frame get displayed so you can use the new Tray
menu.
BalloonDlg.cpp/h - A dialog used by the Tray/Show Balloon command.
The new methods in CSystemTray are:
CSystemTray() - Added parameters for the balloon tooltip.
CreateEx() - Like Create() but has extra parameters for the balloon tooltip.
On NT 4 and 9x, it just calls Create().
ShowBalloon() - Pops up a balloon tooltip over the tray icon (Win 2K only).
HideIcon() - On Win 2K, the icon is hidden (using the API) instead of deleted.
ShowIcon() - On Win 2K, the icon is unhidden. It will reappear in the position
it was in prior to the HideIcon().
HideIcon() and ShowIcon() have a BOOL parameter that's used only by
MoveToRight() to force the icon to be deleted and re-added on Win 2K. This
parameter shouldn't be formally documented, since the caller should still
call just "HideIcon()" and "ShowIcon()".
Bug fixes in CSystemTray:
I added a few AfxIsValidString() calls to validate LPCTSTR parameters.
I also used lstrcpyn() to copy strings into the NOTIFYICONDATA
struct to guard against overrunning the char arrays.

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.

Share

About the Author

Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.