tutorial 23: tray icon
in this tutorial, we will learn how to put icons into system tray and how to create/use a popup menu.
download the example here.
theory:
system tray is the rectangular region in the taskbar where several icons reside. normally, you'll see at least a digital clock in it. you can also put icons in the system tray too. below are the steps you have to perform to put an icon into the system tray:- fill a notifyicondata structure which has the following members:
- cbsize the size of this structure.
- hwnd handle of the window that will receive notification when a mouse event occurs over the tray icon.
- uid a constant that is used as the icon's identifier. you are the one who decides on this value. in case you have more than one tray icons, you will be able to check from what tray icon the mouse notification is from.
- uflags specify which members of this structure are valid
- nif_icon the hicon member is valid.
- nif_message the ucallbackmessage member is valid.
- nif_tip the sztip member is valid.
- ucallbackmessage the custom message that windows will send to the window specified by the hwnd member when mouse events occur over the tray icon. you create this message yourself.
- hicon the handle of the icon you want to put into the system tray
- sztip a 64-byte array that contains the string that will be used as the tooltip text when the mouse hovers over the tray icon.
- call shell_notifyicon which is defined in shell32.inc. this function has the following prototype:
shell_notifyicon proto dwmessage:dword ,pnid:dworddwmessage is the type of message to send to the shell.
nim_add adds an icon to the status area.
nim_delete deletes an icon from the status area.
nim_modify modifies an icon in the status area.
pnid is the pointer to a notifyicondata structure filled with proper values