Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / MFC

Controls-in-controls: An edit box with an icon

Rate me:
Please Sign up or sign in to vote.
4.50/5 (12 votes)
16 Jun 2004Public Domain3 min read 139.9K   2.9K   55  
Adding controls to a CEdit, an edit box with an icon
#if !defined(AFX_ICONEDIT_H__AEA6DB87_1AB8_4BC0_8572_1A0ECB665F4A__INCLUDED_)
#define AFX_ICONEDIT_H__AEA6DB87_1AB8_4BC0_8572_1A0ECB665F4A__INCLUDED_

/////////////////////////////////////////////////////////////////////////////
// CIconWnd window

class CIconWnd : public CStatic
{
// Construction/destruction
public:
	CIconWnd();
	virtual ~CIconWnd();

// Operations
public:
	void SetIcon( HICON icon );

protected:
	afx_msg void OnPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	DECLARE_MESSAGE_MAP()

private:
// Attributes
	HICON	m_icon;
};

/////////////////////////////////////////////////////////////////////////////
// CIconEdit window

class CIconEdit : public CEdit
{
// Construction/destruction
public:
	CIconEdit();
	virtual ~CIconEdit();

// Operations
public:
	void SetIcon(HICON icon);
	void SetIcon(UINT iconres);

protected:
	virtual void PreSubclassWindow();

	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg LRESULT OnSetFont(WPARAM wParam, LPARAM lParam); // Maps to WM_SETFONT
	DECLARE_MESSAGE_MAP()

private:
	void		Prepare();
	void		CreateIcon();

// Attributes
	CIconWnd	m_icon;
	HICON		m_internalIcon;
};

#endif // !defined(AFX_ICONEDIT_H__AEA6DB87_1AB8_4BC0_8572_1A0ECB665F4A__INCLUDED_)

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 A Public Domain dedication


Written By
Software Developer (Senior) Abstrakt Mekanik AB
Sweden Sweden
45 years old, married, three kids.

Started with computers more than 20 years ago on a CBM-64.

Read Theoretical Philosophy at the University of Lund.

Working as a C++ consultant developer.

Science-fiction freak. Enjoy vintage punkrock.

Comments and Discussions