Click here to Skip to main content
15,073,154 members
Articles / Programming Languages / C++
Posted 6 Nov 2000


149 bookmarked

System Tray Icons - Minimize Your Application to the SysTray

Rate me:
Please Sign up or sign in to vote.
4.73/5 (78 votes)
6 Nov 2000CPOL
Minimize your application to system tray instead of the taskbar

Sample Image - TrayIcons.jpg


This article illustrates the use of Shell_NotifyIcon to create and manage System Tray icons. The article explains the basics of this operation and assists you in creating your own 'Minimize To Tray' applications. The source code provided with this article is designed to work with dialog-based applications, but it can easily be modified to work with a CFrameWnd or CWnd based application.

Creating and Using Tray Icons

To create a Tray Icon, you need to call the following shell function: -

BOOL Shell_NotifyIcon( DWORD dwMessage, PNOTIFYICONDATA pnid );

The dwMessage parameter specifies the action to be taken - NIM_ADD, NIM_DELETE, NIM_MODIFY adds, deletes and modifies tray icons respectively.

The pnid parameter is used to customize, create, delete and obtain data from the Tray Icon. (See the MSDN Library for more details about this structure.)

Creating The Application

1. Create a new VC++ dialog based project. For this example, I will call this project MyTray which will contain the CMyTrayApp and CMyTrayDlg classes.

2. Download and extract the DialogTray source code to the root of the project folder

3. From the Project->Add To Project menu, select Files and then select TrayDialog.h and TrayDialog.cpp. This will add a new class to your project named CTrayDialog.

4. Replace the CMyTrayDlg base class with CTrayDialog.

class CMyTrayDlg : public CDialog


#include "TrayDialog.h"

class CMyTrayDlg : public CTrayDialog

5. Replace the other occurrences of CDialog in the MyTrayDlg.cpp file as follows :-

CMyTrayDlg::CMyTrayDlg(CWnd* pParent /*=NULL*/)
  : CDialog(CMyTrayDlg::IDD, pParent)


CMyTrayDlg::CMyTrayDlg(CWnd* pParent /*=NULL*/)	
    : CTrayDialog(CMyTrayDlg::IDD, pParent)

6. Create a menu resource and name it IDR_MENU1

7. In the InitDialog member function, enter the following:

TraySetToolTip("ToolTip for tray icon");

8. Modify the IDD_MYTRAY _DIALOG resource to have a minimize box.

9. Build and run the application

NB : To add tray menu item handlers use the class wizard.

Displaying the tray icon all the time

Simply add a TrayShow() statement to InitDialog() in CMyTrayDlg.cpp, and call TraySetMinimizeToTray(FALSE) to disable minimizing to the tray.

The events that occur in the tray are captured through the following functions:

virtual void OnTrayLButtonDown(CPoint pt);
virtual void OnTrayLButtonDblClk(CPoint pt);

virtual void OnTrayRButtonDown(CPoint pt);
virtual void OnTrayRButtonDblClk(CPoint pt);

virtual void OnTrayMouseMove(CPoint pt);

Feel free to add more events or to improve on these ones.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Daniel Zilcsak
Software Developer
United States United States
No Biography provided

Comments and Discussions

Generalit still works Pin
Southmountain17-Sep-20 7:58
MemberSouthmountain17-Sep-20 7:58 
SuggestionSome Modifications Pin
smart_dummies28-Sep-16 21:16
Membersmart_dummies28-Sep-16 21:16 
QuestionRe: Some Modifications Pin
Member 1296230922-Jan-17 7:11
MemberMember 1296230922-Jan-17 7:11 
QuestionTrayShow() leads the minimize button becoming invalid Pin
Scarlettlee16-May-13 0:17
professionalScarlettlee16-May-13 0:17 
QuestionHow to do If I want it be Tray Mode while begging? Pin
vannes23-Dec-11 1:12
Membervannes23-Dec-11 1:12 
AnswerRe: How to do If I want it be Tray Mode while begging? Pin
EsenChang5-Aug-12 17:38
MemberEsenChang5-Aug-12 17:38 
Questionprogramatically minimizing does not work on VS 2005 Pin
Erik17-Oct-11 19:01
MemberErik17-Oct-11 19:01 
QuestionCWinApp Pin
lukegorman25-Aug-11 23:52
Memberlukegorman25-Aug-11 23:52 
AnswerRe: CWinApp Pin
lukegorman26-Aug-11 0:13
Memberlukegorman26-Aug-11 0:13 
QuestionLicencing Pin
rainer.hochdorfer27-Apr-10 22:06
Memberrainer.hochdorfer27-Apr-10 22:06 
AnswerRe: Licencing Pin
Daniel Zilcsak28-Apr-10 3:29
MemberDaniel Zilcsak28-Apr-10 3:29 
AnswerRe: Licencing Pin
rainer.hochdorfer28-Apr-10 6:02
Memberrainer.hochdorfer28-Apr-10 6:02 
GeneralThanks just perfect Pin
asierra0111-Jan-10 9:14
Memberasierra0111-Jan-10 9:14 
GeneralRight Click Menu Pin
Shup15-May-09 1:20
MemberShup15-May-09 1:20 
GeneralThank you! Pin
DevMan7712-May-09 8:20
MemberDevMan7712-May-09 8:20 
GeneralChanging tray icon while minimized Pin
eight26-Mar-09 2:21
Membereight26-Mar-09 2:21 
GeneralThanks!!! Pin
IAM...15-Feb-09 5:56
MemberIAM...15-Feb-09 5:56 
QuestionOnly minimizing to tray in my application? Pin
Alexander Peter31-Oct-08 5:03
MemberAlexander Peter31-Oct-08 5:03 
QuestionBalloon Tip?? Pin
thanasis_rassp12-Aug-08 3:16
Memberthanasis_rassp12-Aug-08 3:16 
AnswerRe: Balloon Tip?? Pin
varandas7924-Sep-08 5:25
Membervarandas7924-Sep-08 5:25 
GeneralBug in CTrayDialog::OnSysCommand preventing sizing Pin
EricGen24-Mar-08 23:02
MemberEricGen24-Mar-08 23:02 
GeneralSystem get slow... Pin
Member 385006728-Feb-08 21:52
MemberMember 385006728-Feb-08 21:52 
Generalsmall but useful demo Pin
lilesh10-Oct-07 22:33
Memberlilesh10-Oct-07 22:33 
QuestionHow can I get my app on the tray at the very beginning? Pin
pjvv126-Sep-07 7:31
Memberpjvv126-Sep-07 7:31 
AnswerSolution Pin
lilesh10-Oct-07 23:01
Memberlilesh10-Oct-07 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.