Click here to Skip to main content
15,896,477 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.
// ConfigHeaderCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "ConfigListCtrl.h"
#include "ConfigHeaderCtrl.h"

// CConfigHeaderCtrl

IMPLEMENT_DYNAMIC(CConfigHeaderCtrl, CHeaderCtrl)

CConfigHeaderCtrl::CConfigHeaderCtrl()
{
}

CConfigHeaderCtrl::~CConfigHeaderCtrl()
{
}


BEGIN_MESSAGE_MAP(CConfigHeaderCtrl, CHeaderCtrl)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_LBUTTONDOWN()
	ON_MESSAGE(HDM_LAYOUT, OnLayout)
END_MESSAGE_MAP()

// CConfigHeaderCtrl message handlers

LRESULT CConfigHeaderCtrl::OnLayout(WPARAM wParam, LPARAM lParam)
{
	LPHDLAYOUT lphdLayout = (LPHDLAYOUT)lParam;

	lphdLayout->prc;

	((CConfigListCtrl *)GetParent())->OnResizeColumn();

	return CHeaderCtrl::DefWindowProc(HDM_LAYOUT, 0, lParam);
}

void CConfigHeaderCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	HDHITTESTINFO hdHitTestInfo;

	hdHitTestInfo.pt.x = point.x;
	hdHitTestInfo.pt.y = point.y;

	SendMessage(HDM_HITTEST, 0, (long)&hdHitTestInfo);

	if (hdHitTestInfo.flags == HHT_ONDIVIDER || hdHitTestInfo.flags == HHT_ONDIVOPEN)
	{
// Note: the default behaviour does not handle HHT_ONDIVOPEN (hidden column).
// In Excel, the equivalent of HHT_ONDIVOPEN will behave the same way as with HHT_ONDIVIDER,
// that is, set the column width to the minimum width required to fully display all items of column.	
		((CConfigListCtrl *)GetParent())->SetColumnMinWidth(hdHitTestInfo.iItem);
	}
	else
		CHeaderCtrl::OnLButtonDblClk(nFlags, point);
}

void CConfigHeaderCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
	((CConfigListCtrl *)GetParent())->OnHeaderLButtonDown(nFlags, point);
	CHeaderCtrl::OnLButtonDown(nFlags, point);
}


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