Click here to Skip to main content
15,885,925 members
Articles / Desktop Programming / MFC

Create Icons at Runtime and Show Them in the System Tray

Rate me:
Please Sign up or sign in to vote.
4.66/5 (18 votes)
10 Jun 2008CPOL4 min read 75.1K   2.2K   78  
Create dynamic icons at runtime and show them in the system tray
// DynIconDlg.h : header file
//

#pragma once


#define TIMER1 1
#define WM_TRAY WM_APP + 1

#define ICON_VALUE1 1
#define ICON_VALUE2 2



// CDynIconDlg dialog
class CDynIconDlg : public CDialog
{
// Construction
public:
	CDynIconDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_DYNICON_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

public:
	int m_nValue1;
	int m_nValue2;

	HICON m_hIcon1;
	HICON m_hIcon2;

	CString m_strTooltip;

	BOOL m_bActiv;
	BOOL m_bFirstDefaultIcon;
	BOOL m_bFirstIcon1;
	BOOL m_bFirstIcon2;

	void ChangeValues(void);
	
	void CreateIcons(void);
	void CreateIcon1(void);
	void CreateIcon2(void);

	void PushIcons(void);
	void PushIcon1(void);
	void PushIcon2(void);

	void ClearIcon1(void);
	void ClearIcon2(void);

	void SetDefaultIconInTray(void);
	void ClearDefaultIconInTray(void);


	LRESULT	OnTray(WPARAM wParam, LPARAM lParam);	

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();

	DECLARE_MESSAGE_MAP()

	afx_msg void OnBnClickedOk();
	afx_msg void OnBnClickedStart();
	afx_msg void OnBnClickedStop();
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	


};

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)


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

Comments and Discussions