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(5)
 [1] IainWhite | 2006-06-21 09: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 23: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 22: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-14 02: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-27 04:27:50

Nice job m8
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[119194]
2D Rotated Rectangles Collision Detection[90098]
Keyboard Hook[78635]
HTTP Proxy[41966]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11602]
PS2 Mouse Driver[7002]
Wave Format Player[5828]
Reading FAT12[5652]

All rights reserved to RageStorm © 2009