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

24 Bit Color Icon in System Tray

, 15 Mar 2004
An article on displaying icons with more than 256 colors in system tray
systray24.zip
SysTray24
Debug
res
24 bit.bmp
SysTray24.ico
SysTray24.clw
SysTray24.dsp
SysTray24.dsw
/////////////////////////////////////////////////////////////////////////////
// SystemTray.h : header file
//
// Written by Chris Maunder (chrismaunder@codeguru.com)
// Copyright (c) 1998.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name is included. If 
// the source code in  this file is used in any commercial application 
// then acknowledgement must be made to the author of this file 
// (in whatever form you wish).
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to your
// computer, causes your pet cat to fall ill, increases baldness or
// makes you car start emitting strange noises when you start it up.
//
// Expect bugs.
// 
// Please use and enjoy. Please let me know of any bugs/mods/improvements 
// that you have found/implemented and I will fix/incorporate them into this
// file. 

#ifndef _INCLUDED_SYSTEMTRAY_H_
#define _INCLUDED_SYSTEMTRAY_H_

#include <afxtempl.h>

/////////////////////////////////////////////////////////////////////////////
// CSystemTray window

//##ModelId=3A45CC77010D
class CSystemTray : public CWnd
{
// Construction/destruction
public:
	//##ModelId=3A45CC770119
    CSystemTray();
	//##ModelId=3A45CC77011A
    CSystemTray(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID);
	//##ModelId=3A45CC770120
    virtual ~CSystemTray();

    DECLARE_DYNAMIC(CSystemTray)

// Operations
public:
	CMenu m_menu;
	BOOL ModifyMenu(UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem = 0, LPCTSTR lpszNewItem = NULL);
	//##ModelId=3A45CC770122
    BOOL Enabled() { return m_bEnabled; }
	//##ModelId=3A45CC770123
    BOOL Visible() { return !m_bHidden; }

    // Create the tray icon
	//##ModelId=3A45CC770124
    Create(CWnd* pParent, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID);

    // Change or retrieve the Tooltip text
	//##ModelId=3A45CC77012D
    BOOL    SetTooltipText(LPCTSTR pszTooltipText);
	//##ModelId=3A45CC77012F
    BOOL    SetTooltipText(UINT nID);
	//##ModelId=3A45CC770131
    CString GetTooltipText() const;

    // Change or retrieve the icon displayed
	//##ModelId=3A45CC770133
    BOOL  SetIcon(HICON hIcon);
	//##ModelId=3A45CC770135
    BOOL  SetIcon(LPCTSTR lpszIconName);
	//##ModelId=3A45CC770138
    BOOL  SetIcon(UINT nIDResource);
	//##ModelId=3A45CC77013A
    BOOL  SetStandardIcon(LPCTSTR lpIconName);
	//##ModelId=3A45CC77013C
    BOOL  SetStandardIcon(UINT nIDResource);
	//##ModelId=3A45CC77013E
    HICON GetIcon() const;
	//##ModelId=3A45CC770140
    void  HideIcon();
	//##ModelId=3A45CC770141
    void  ShowIcon();
	//##ModelId=3A45CC770142
    void  RemoveIcon();
	//##ModelId=3A45CC770143
    void  MoveToRight();

    // For icon animation
	//##ModelId=3A45CC770147
    BOOL  SetIconList(UINT uFirstIconID, UINT uLastIconID); 
	//##ModelId=3A45CC77014A
    BOOL  SetIconList(HICON* pHIconList, UINT nNumIcons); 
	//##ModelId=3A45CC77014D
    BOOL  Animate(UINT nDelayMilliSeconds, int nNumSeconds = -1);
	//##ModelId=3A45CC770150
    BOOL  StepAnimation();
	//##ModelId=3A45CC770151
    BOOL  StopAnimation();

    // Change menu default item
	//##ModelId=3A45CC770152
    void GetMenuDefaultItem(UINT& uItem, BOOL& bByPos);
	//##ModelId=3A45CC770157
    BOOL SetMenuDefaultItem(UINT uItem, BOOL bByPos);

    // Change or retrieve the window to send notification messages to
	//##ModelId=3A45CC77015A
    BOOL  SetNotificationWnd(CWnd* pNotifyWnd);
	//##ModelId=3A45CC77015C
    CWnd* GetNotificationWnd() const;

    // Default handler for tray notification message
	//##ModelId=3A45CC77015E
    virtual LRESULT OnTrayNotification(WPARAM uID, LPARAM lEvent);

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CSystemTray)
	protected:
	//##ModelId=3A45CC770162
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	//}}AFX_VIRTUAL

// Implementation
protected:
	//##ModelId=3A45CC770168
    void Initialise();

	//##ModelId=3A45CC770169
    BOOL            m_bEnabled;   // does O/S support tray icon?
	//##ModelId=3A45CC770195
    BOOL            m_bHidden;    // Has the icon been hidden?
	//##ModelId=3A45CC7701A6
    NOTIFYICONDATA  m_tnd;

	//##ModelId=3A45CC7701AA
    CArray<HICON, HICON> m_IconList;
	//##ModelId=3A45CC7701AB
    static UINT  m_nIDEvent;
	//##ModelId=3A45CC7701B5
    UINT         m_uIDTimer;
	//##ModelId=3A45CC7701B6
    int          m_nCurrentIcon;
	//##ModelId=3A45CC7701B8
    COleDateTime m_StartTime;
	//##ModelId=3A45CC7701C4
    int          m_nAnimationPeriod;
	//##ModelId=3A45CC7701C5
    HICON        m_hSavedIcon;
	//##ModelId=3A45CC7701C6
    UINT         m_DefaultMenuItemID;
	//##ModelId=3A45CC7701C7
    BOOL         m_DefaultMenuItemByPos;

// Generated message map functions
protected:
	//{{AFX_MSG(CSystemTray)
	//##ModelId=3A45CC7701D4
	afx_msg void OnTimer(UINT nIDEvent);
	//}}AFX_MSG

    DECLARE_MESSAGE_MAP()
};


#endif

/////////////////////////////////////////////////////////////////////////////

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Muhammad Asif Khan
Web Developer
Pakistan Pakistan
Masters of Computer Sciences from International Islamic University Islamabad, Pakistan
Love programming in C++ and VC.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 16 Mar 2004
Article Copyright 2004 by Muhammad Asif Khan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid