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

Changing Row Height in an owner drawn Control

Rate me:
Please Sign up or sign in to vote.
4.89/5 (25 votes)
8 Nov 2001CPOL4 min read 359.5K   6.7K   88  
Changing the Row Height in an owner drawn List View Control
#if !defined(AFX_LISTCTRLEX_H__30509656_B8A5_11D5_8CEB_00E098800D6B__INCLUDED_)
#define AFX_LISTCTRLEX_H__30509656_B8A5_11D5_8CEB_00E098800D6B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ListCtrlEx.h : header file
//
#include "HeaderCtrlEx.h"
/////////////////////////////////////////////////////////////////////////////
// CListCtrlEx window


static _TCHAR *_gszColumnLabel[4] =
{
	_T("Color\nName"), _T("Red\nColor"), _T("Blue\nColor"), _T("Black\nColor")
};


static int _gnColumnWidth[4] =
{
	150, 100, 150, 80
};


static int _gnColumnFmt[4] =
{
	LVCFMT_LEFT, LVCFMT_RIGHT, LVCFMT_RIGHT
};


static _TCHAR *_gszItem[2][4] =
{
	_T("Yellow\nY"),  _T("255\n255"), _T("30"), _T("50"),
	_T("Red\nR"),     _T("255"), _T("30"), _T("50") 
};

class CListCtrlEx : public CListCtrl
{
// Construction
public:
	CListCtrlEx();

// Attributes
public:
	int		m_nLinesPerRow;	
	int     m_nColumns, m_nRows ;

	CFont			m_NewListFont;
	CHeaderCtrlEx	m_HeaderCtrl ;

	void OnInitialUpdate() ;
	void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) ;

	void SetNoOfLinesPerRow(int n)  { m_nLinesPerRow = n ; }
	void SetNoOfColumns(int n=1)	{ m_nColumns = n ; }
	void SetNoOfRows(int n=0)		{ m_nRows = n ; }

	afx_msg LRESULT	OnSetFont(WPARAM wParam, LPARAM lParam);
	afx_msg void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);

// Operations
public:

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

// Implementation
public:
	virtual ~CListCtrlEx();

	// Generated message map functions
protected:
	//{{AFX_MSG(CListCtrlEx)
	afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_LISTCTRLEX_H__30509656_B8A5_11D5_8CEB_00E098800D6B__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 The Code Project Open License (CPOL)


Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions