Code Snippets
Code Samples

The Blog
Our Projects

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

Tutorial - System Tray
Uploaded at:30-May-03
The system tray icon is easy but impressive! :)
OK, there is a struct called "NOTIFYICONDATA"(NID) which contains all information
related to our System Tray Icon. So in order to create an icon we first need to set some members of the struct:
NID.cbSize = sizeof(NID); // Size of the structure duh :)
NID.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
// The icon that will be shown in the systray.
NID.uCallbackMessage = WM_USER + 1; // Our user defined message.
// (Windows will send us messages when user pressed on our icon)
NID.hWnd = hWnd;
// Handle to the window that will receive the notifications.
NID.uID = WM_USER + 2; // Icon ID in systray...
strcpy(NID.szTip, "System Tray Icon[QSoft]"); // The tooltip string.
// We say our struct has an Icon, a ToolTip // and we want to get notifications.
// Now we need to "ADD" our icon too.. Shell_NotifyIcon(NIM_ADD, &NID); // Now let's change some variable in the struct while your application
// is running, for instance let's change the icon and tooltip: NID.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2));
strcpy(NID.szTip, "MODIFIED System Tray Icon[QSoft]");
// BTW-when you MODIFY it means that the other variables were set before! Shell_NotifyIcon(NIM_MODIFY, &NID); // Don't forget to delete it when you close your application! Shell_NotifyIcon(NIM_DELETE, &NID);

That was it...
Small source that does a lot :)
Hope you'll find it useful!
Take a look at the samples..

Source Code:
Visual C++ 6 - SysTray.zip
Visual C++ 6 - SysTray2.zip

User Contributed Comments(6)
 [1] IainWhite | 2006-06-21 05:01:55

Ahh - SysTray.zip is fascinating. I've been searching for something like this for quite a while.

I compiled it using Dev-C++ and when I checked the CPU usage, it was 98%, whether it was minimized to the system tray or not. Is there any way of getting this down to a much more reasonable level, say 1 or 2%?
 [2] arkon | 2006-07-13 19:45:53

When explorer crashes and runs again you want to know about it and then add the icon again.
This is simply done by the following snippet:

in WindowProc:
static UINT ExpMsgId;

if (ExpMsgId && msg == ExpMsgId) {
 Shell_NotifyIcon(NIM_ADD, &NID);
 return 0;

switch (msg)
 case WM_CREATE:
  ExpMsgId = RegisterWindowMessage("TaskbarCreated");
 return 0;

There you go.
 [3] Q_Q | 2007-08-06 18:09:12

hi man!, do u know how to do this with a DialogBox???

I mean, this is for a window, with its procedure and stuff, but I don't want to do this with a window,
I want this with a DialogBox, and send it to the tray icon.

Instead of using a window, using a dialog box. I tried hiding the window and then showing the dialog
box, but nothing.... :/ !!!
 [4] arkon | 2007-08-13 22:31:57

i think you did something wrong then. it is supposed to be the same.
if you can narrow down your code and send me the sample i will take a look myself.
 [5] Brlocky | 2007-12-26 23:27:50

Nice job m8
 [6] barbara | 2014-05-07 03:35:07

I've read some great stuff here, and I definitely learned a lot from you. Thank you!
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
::Top 5 Tutorials::
Embedded Python[105388]
2D Rotated Rectangles Collision Detection[78700]
Keyboard Hook[68403]
HTTP Proxy[35813]

::Top 5 Samples::
2D ColDet Rotated Rectangles[10558]
PS2 Mouse Driver[6059]
Wave Format Player[4945]
Reading FAT12[4826]

All rights reserved to RageStorm © 2009