Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Adding Icons to the System Tray

, 2 Aug 2003
A class for adding icons to the system tray
hatrsystemtray.zip
systemtraysdk_demo.zip
SystemTraySDK_demo
Release
TaskbarDemo.exe
res
icon1.ico
icon2.ico
icon3.ico
icon4.ico
TaskbarDemo.ICO
TaskbarDemo.dsp
TaskbarDemo.dsw
systemtray_demo.zip
systemtray_demo
Release
SystemTrayDemo.exe
RES
Cmdbar.bmp
icon1.ico
icon2.ico
icon3.ico
icon4.ico
SystemTrayDemo.ico
SystemTrayDemoDoc.ico
Toolbar.bmp
SystemTrayDemo.dsp
SystemTrayDemo.dsw
SystemTrayDemoCE.dsp
SystemTrayDemoCE.dsw
systemtray_src.zip
// BalloonDlg.cpp : implementation file
//

#include "stdafx.h"
#include "systemtraydemo.h"
#include "BalloonDlg.h"
#include "systemtray.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBalloonDlg dialog


CBalloonDlg::CBalloonDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBalloonDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBalloonDlg)
	m_sBalloonText = _T("");
	m_sBalloonTitle = _T("");
	m_uTimeout = 0;
	//}}AFX_DATA_INIT
}


void CBalloonDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBalloonDlg)
	DDX_Control(pDX, IDC_COMBO, m_combo);
	DDX_Text(pDX, IDC_BALLOON_TEXT, m_sBalloonText);
	DDX_Text(pDX, IDC_BALLOON_TITLE, m_sBalloonTitle);
	DDX_Text(pDX, IDC_TIMEOUT, m_uTimeout);
	DDV_MinMaxUInt(pDX, m_uTimeout, 10, 30);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBalloonDlg, CDialog)
	//{{AFX_MSG_MAP(CBalloonDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBalloonDlg message handlers

BOOL CBalloonDlg::OnInitDialog() 
{
    m_uTimeout = 10;

	CDialog::OnInitDialog();

    ((CSpinButtonCtrl*) GetDlgItem ( IDC_TIMEOUT_SPIN ))->SetRange ( 10, 30 );

    m_imglist.Create ( 16, 16, ILC_COLOR4 | ILC_MASK, 4, 1 );

    m_imglist.Add ( ::LoadIcon ( NULL, IDI_INFORMATION ));
    m_imglist.Add ( ::LoadIcon ( NULL, IDI_WARNING ));
    m_imglist.Add ( ::LoadIcon ( NULL, IDI_ERROR ));

    m_combo.SetImageList ( &m_imglist );

    COMBOBOXEXITEM item;

    item.mask = CBEIF_TEXT;
    item.iItem = 0;
    item.pszText = _T("None");
    m_combo.InsertItem ( &item );

    item.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
    item.iItem = 1;
    item.pszText = _T("Information");
    item.iImage = item.iSelectedImage = 0;
    m_combo.InsertItem ( &item );

    item.pszText = _T("Warning");
    item.iItem = 2;
    item.iImage = item.iSelectedImage = 1;
    m_combo.InsertItem ( &item );

    item.pszText = _T("Error");
    item.iItem = 3;
    item.iImage = item.iSelectedImage = 2;
    m_combo.InsertItem ( &item );

    m_combo.SetCurSel ( 0 );

    return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBalloonDlg::OnOK() 
{
#ifdef SYSTEMTRAY_USEW2K
    switch ( m_combo.GetCurSel() )
        {
        case 0: m_dwIcon = NIIF_NONE;    break;
        case 1: m_dwIcon = NIIF_INFO;    break;
        case 2: m_dwIcon = NIIF_WARNING; break;
        case 3: m_dwIcon = NIIF_ERROR;   break;
        }
#endif

	CDialog::OnOK();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.
 
His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.
 
He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.
 
Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 3 Aug 2003
Article Copyright 1999 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid