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

CTrayIcon - System Tray Icon Wrapper

, 6 Jun 2007
An article exhibiting a wrapper class for System Taskbar icon.
ctrayicon_demo.zip
CTrayIconDemo.exe
ctrayicon_src.zip
res
CTrayIconDemo.ico
ico00001.ico
ico00002.ico
idr_main.ico
Thumbs.db
CTrayIconDemo.aps
CTrayIconDemo.clw
CTrayIconDemo.dsp
CTrayIconDemo.dsw
CTrayIconDemo.ncb
CTrayIconDemo.opt
CTrayIconDemo.plg
demo.zip
Demo
CTrayIconDemo.exe
src.zip
Src
CTrayIconDemo.clw
CTrayIconDemo.dsp
CTrayIconDemo.dsw
res
CTrayIconDemo.ico
// IconData.h : header file

#pragma once

class CIconData;

// Synomym for CIconData pointer
typedef CIconData* IconDataPtr;

// CIconData

class CIconData: public CObject
{
public:

	// Quad parameter constructor
	CIconData(	unsigned int uDefaultIconID, 
				LPSTR lpToolTip,
				unsigned int uHoverIconID = 0, 
				HICON hIcon = NULL)
	{
		SetDefaultIconID(uDefaultIconID);	
		SetHoverIconID(uHoverIconID);
		SetToolTip(lpToolTip);		
		SetIconHandler(hIcon);	
		LoadIcon(GetDefaultIconID());
	}

	// Copy constructor
	CIconData(const CIconData &pIconData)
	{
		CIconData(pIconData.m_uDefaultIconID, pIconData.m_lpToolTip, pIconData.m_uHoverIconID, pIconData.m_hIcon);
	}


	// Gets the selected icon's identifer
	unsigned int GetIconID() const
	{
		return m_uIconID;
	}

	// Gets the default icon identfier
	unsigned int GetDefaultIconID() const
	{
		return m_uDefaultIconID;
	}

	// Sets the default icon identifier
	void SetDefaultIconID(unsigned int uIconID)
	{
		m_uDefaultIconID = uIconID;		
	}

	// Gets the hover icon identifer
	unsigned int GetHoverIconID() const
	{
		return m_uHoverIconID;
	}

	// Sets the hover icon identifier
	void SetHoverIconID(unsigned int uIconID)
	{
		m_uHoverIconID = uIconID;
	}

	// Gets the tooltip
	LPSTR GetToolTip() const
	{
		return m_lpToolTip;
	}

	// Sets the tooltip
	void SetToolTip(LPSTR lpToolTip)
	{
		m_lpToolTip = lpToolTip;
		/*m_lpToolTip = new char[strlen(lpToolTip)];
		strcpy(m_lpToolTip, lpToolTip);*/
	}

	// Gets the icon handler
	HICON GetIconHandler() const
	{
		return m_hIcon;
	}

	// Selects and loads the speciifed icon into memory
	bool LoadIcon(unsigned int uIconID)
	{
		if(uIconID == m_uDefaultIconID || uIconID == m_uHoverIconID)
		{
			SetIconID(uIconID);
			SetIconHandler(AfxGetApp()->LoadIcon(GetIconID()));
			return true;
		}

		return false;
	}

	// Desctructor
	~CIconData()
	{
		//delete[] m_lpToolTip;
		m_lpToolTip = 0;
	}

private:

	CIconData(){}

	void SetIconID(unsigned int uIconID)
	{
		if(uIconID != 0)
			m_uIconID = uIconID;		
	}

	void SetIconHandler(HICON hIcon)
	{
		if(hIcon != NULL)
		{
			if(m_hIcon != NULL)
				DestroyIcon(m_hIcon);
			m_hIcon = hIcon;
		}
	}

	unsigned int m_uIconID;

	unsigned int m_uDefaultIconID;

	unsigned int m_uHoverIconID;	

	HICON m_hIcon;

	LPSTR m_lpToolTip;
};

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

No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 6 Jun 2007
Article Copyright 2004 by Muneeb Ahmed Awan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid