Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C++

CTrayIcon - System Tray Icon Wrapper

Rate me:
Please Sign up or sign in to vote.
3.17/5 (14 votes)
6 Jun 20078 min read 175K   5K   47  
An article exhibiting a wrapper class for System Taskbar icon.
#if !defined(TRAYICON_H)
#define TRAYICON_H

const UINT WM_TI_TASKBARCREATED = ::RegisterWindowMessage(_T("TaskbarCreated"));

const UINT WM_TI_NOTIFYICON = ::RegisterWindowMessage(_T("NotifyIcon"));

class CTrayIconMouseMsgHandler;

typedef CTrayIconMouseMsgHandler* MouseMsgHandlerPtr;

class CTrayIcon:public CObject
{
public:

	CTrayIcon(HWND hWnd, UINT uIconID, HICON hIcon, LPSTR lpToolTip, MouseMsgHandlerPtr *pMouseMsgHandler, int nHandlers);


	~CTrayIcon();

	void SetTrayIcon(HWND hWnd, UINT uIconID, HICON hIcon, LPSTR lpToolTip);

	void SetMouseMsgHandler(MouseMsgHandlerPtr *pMouseMsgHandler, int nHandlers);

	BOOL AddIcon();

	BOOL DeleteIcon();

	LRESULT OnTaskBarCreated(WPARAM wParam, LPARAM lParam);

	void OnNotifyIcon(WPARAM wParam, LPARAM lParam);	

private:
	
	CTrayIcon();

	HWND m_hWnd;

	UINT m_uIconID;

	HICON m_hIcon;

	LPSTR m_lpToolTip;

	MouseMsgHandlerPtr *m_pMouseMsgHandler;

	int m_nHandlers;
};

class CTrayIconMouseMsgHandler: public CObject
{
public:

	CTrayIconMouseMsgHandler()
	{
		m_uMouseMsgID = WM_LBUTTONDBLCLK;
	}

	CTrayIconMouseMsgHandler(UINT uMouseMsgID)
	{
		m_uMouseMsgID = uMouseMsg;
	}

	virtual void MouseMsgHandler(){}

	UINT GetMouseMsgID()
	{
		return m_uMouseMsgID;
	}

	void SetMouseMsgID(UINT uMouseMsgID)
	{
		m_uMouseMsgID = uMouseMsgID;
	}

private:
	
	UINT m_uMouseMsgID;
};

#endif // TRAYICON_H

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


Written By
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions