Click here to Skip to main content
15,893,814 members
Articles / Desktop Programming / MFC

An MFC-CListCtrl derived class that allows other ‘controls’ to be inserted into a particular cell

Rate me:
Please Sign up or sign in to vote.
4.92/5 (54 votes)
5 Jan 2014CPOL12 min read 168.1K   14K   160  
A class derived from CListCtrl that allows edit controls, combo boxes, check boxes, date pickers, and color pickers to be inserted into or removed from particular cells extremely easily. The inserted 'controls' are not CWnd-derived.
#pragma once

#include "CellCtrl.h"

#define DEFAULT_BUTTON_WIDTH (::GetSystemMetrics(SM_CXVSCROLL) + ::GetSystemMetrics(SM_CXEDGE))

class CCellButton : virtual public CCellCtrl  
{
public:
	CCellButton();
	virtual ~CCellButton();
	virtual BOOL OnPressButton(UINT nFlags, CPoint point) = 0; 
	virtual BOOL OnLButtonDown(UINT nFlags, CPoint point);
	virtual BOOL OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar){return TRUE;}
	virtual BOOL OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar){return TRUE;}
	virtual void OnEnter(){}
	virtual void OnEscape(){}
	virtual void OnHotMouseMove(UINT nFlags, CPoint point);
	virtual void OnKillHot();
protected:
	RECT				m_rcClickRect; // the rectangle sensitive to a click
	BOOL				m_bIsButtonHot;
	inline int GetThemeButtonStateId(BOOL PressedState, int NormalStateId, int HotStateId, int PressedStateId, int DisabledStateId)
	{
		if (IsDisabled())
			return DisabledStateId;
		if (PressedState)
			return PressedStateId;
		if (m_bIsButtonHot)
			return HotStateId;

		return NormalStateId;
	}
};

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
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions