Click here to Skip to main content
13,766,617 members
Click here to Skip to main content
Add your own
alternative version


147 bookmarked
Posted 6 Nov 2000
Licenced CPOL

System Tray Icons - Minimize Your Application to the SysTray

, 6 Nov 2000
Rate this:
Please Sign up or sign in to vote.
Minimize your application to system tray instead of the taskbar
<!-- Link to source file download --> <!-- Article image -->

Sample Image - TrayIcons.jpg

<!-- Add the rest of your HTML here -->


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

You may also be interested in...

Comments and Discussions

GeneralSome bugs Pin
rrrado7-Mar-05 1:43
memberrrrado7-Mar-05 1:43 
GeneralRe: Some bugs Pin
rrrado7-Mar-05 3:26
memberrrrado7-Mar-05 3:26 
GeneralGreat job -- small improvement Pin
Hard Hat23-Feb-05 2:21
memberHard Hat23-Feb-05 2:21 
GeneralTerminating from TaskManager Pin
Alan Buchanan23-Feb-05 1:02
memberAlan Buchanan23-Feb-05 1:02 
GeneralRe: Terminating from TaskManager Pin
Anonymous23-Feb-05 15:36
memberAnonymous23-Feb-05 15:36 
GeneralRe: Terminating from TaskManager Pin
Anonymous18-Apr-05 21:45
memberAnonymous18-Apr-05 21:45 
GeneralRe: Terminating from TaskManager Pin
TaLF25-Jun-05 14:17
memberTaLF25-Jun-05 14:17 
GeneralRe: Solution - Terminating from TaskManager Pin
IVarshilov24-May-09 23:53
memberIVarshilov24-May-09 23:53 
GeneralStart Dialog Minimized to SysTray Pin
codehar13-Feb-05 20:04
membercodehar13-Feb-05 20:04 
GeneralRe: Start Dialog Minimized to SysTray Pin
mysticwolf9-Mar-05 7:18
membermysticwolf9-Mar-05 7:18 
GeneralRe: Start Dialog Minimized to SysTray Pin
bubis14-Sep-05 3:57
memberbubis14-Sep-05 3:57 
AnswerRe: Start Dialog Minimized to SysTray Pin
CodeWatcher27-Oct-05 14:28
memberCodeWatcher27-Oct-05 14:28 
GeneralRe: Start Dialog Minimized to SysTray Pin
binyo6618-May-09 17:55
memberbinyo6618-May-09 17:55 
GeneralGreat Code - Read if using Checkboxes on Popup Menus Pin
slinsell21-Jan-05 23:49
memberslinsell21-Jan-05 23:49 
GeneralRe: Great Code - Read if using Checkboxes on Popup Menus Pin
blongtq15-Jun-05 23:25
memberblongtq15-Jun-05 23:25 
GeneralNice work Pin
26-Dec-04 2:47
suss26-Dec-04 2:47 
GeneralOne more problem Pin
Mich261-Dec-04 20:46
memberMich261-Dec-04 20:46 
GeneralRe: One more problem Pin
_bko22-May-05 23:23
member_bko22-May-05 23:23 
General&quot;but it can easily be modified to work with a CFrameWnd or CWnd based application&quot; Pin
anderslundsgard21-Nov-04 8:14
memberanderslundsgard21-Nov-04 8:14 
GeneralOpening another application Pin
Ritcho26-Sep-04 4:53
memberRitcho26-Sep-04 4:53 
GeneralRe: Opening another application Pin
AnonExerc29-Oct-04 1:23
memberAnonExerc29-Oct-04 1:23 
GeneralRe: Opening another application Pin
EpicBoy28-Jan-05 1:40
memberEpicBoy28-Jan-05 1:40 
GeneralRe: Opening another application Pin
EpicBoy28-Jan-05 1:47
memberEpicBoy28-Jan-05 1:47 
QuestionWhat's the problem???? Pin
casper23418-May-04 3:41
membercasper23418-May-04 3:41 
AnswerRe: What's the problem???? Pin
Hesterumpe20-May-04 1:25
memberHesterumpe20-May-04 1:25 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05-2016 | 2.8.181114.1 | Last Updated 7 Nov 2000
Article Copyright 2000 by Daniel Zilcsak
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid