Click here to Skip to main content
15,896,269 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.5K   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
// popupcolorbar.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CPopupColorBar window

#include "ListCtrlCellWnd.h"

class CCellColorCtrl;
class CColorCtrl;

#define	FLAG_COLOR_SELECTED			0x00000001
#define FLAG_COLOR_HIGLIGHTED		0x00000002

struct COLOR_INFO
{
	COLORREF	m_ColorRef;
	LPCTSTR		m_Name;
	RECT		m_Rect;
	LONG		m_StatusFlag;

	COLOR_INFO(COLORREF	ColorRef = 0, LPCTSTR Name = _T(""), RECT Rect = RECT()) : m_ColorRef(ColorRef), m_Name(Name), m_Rect(Rect), m_StatusFlag(0)
	{}
};

class ColorInfoLess
{
public:
	bool operator () (const COLOR_INFO *a, const COLOR_INFO *b) const
	{
		return a->m_ColorRef < b->m_ColorRef;
	}
};

class CPopupColorBar : public CListCtrlCellWnd
{
// Construction
public:
	CPopupColorBar();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CPopupColorBar)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CPopupColorBar();
	void Create(HWND hParentWnd, CCellColorCtrl *pCellColorCtrl);
	BOOL PreTranslateMessage(MSG* pMsg);
	void GetBoundingRect(const RECT &rcCellBounding, RECT &rcBounding, BOOL Downwards = TRUE);
	void OpenDropDown(const COLORREF ColorRef);
	void OnEnter();	
	// Generated message map functions
protected:
	//{{AFX_MSG(CPopupColorBar)
	afx_msg void OnPaint();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	CArray<COLOR_INFO>						m_ColorInfo;
	CRect									m_RectOther, m_RectOtherColor;

	short								m_ColorColumns, m_ColorRows, m_SelColor, m_HighlightColor;
	BOOL								m_ShowOtherButton, m_HighlightOtherButton, m_ShowOtherColor;
	COLORREF							m_ActiveColor;
	CToolTipCtrl						*m_pToolTip;
	void PaintButtons(CDC* pDC);
	void PaintButton(CDC* pDC, CRect Rect, COLORREF ColorRef, LONG status);
	void ComputeDetails();
	short GetColorButtonFromPt(const CPoint& point);
	void FireColor(COLORREF ColorRef);
	void DrawSeparator(CDC* pDC);
	void DrawOtherButton(CDC* pDC);
	void DisplayColorDialog();
};

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