Click here to Skip to main content
15,887,683 members
Articles / Desktop Programming / WTL

A fast and lightweight cell control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (31 votes)
11 Mar 2008CPOL1 min read 90.9K   4.5K   81  
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.
/* -------------------------------------------------------------------------
//MyCell Library - MyCell version 1.0
//
// This file is a part of the MyCell Library.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.txt at this distribution. By using
// this software in any fashion, you are agreeing to be bound by the terms
// of this license. You must not remove this notice, or any other, from
// this software.
//
// Creator: yanxueming
// Email: xueming.yan@gmail.com
// -----------------------------------------------------------------------*/
#pragma once
#include "base.h"

#define OCN_BASE			NM_FIRST
#define OCN_LBUTTONDBLCLK	(OCN_BASE+WM_LBUTTONDBLCLK)
#define OCN_RBUTTONDOWN	(OCN_BASE+WM_RBUTTONDOWN)
#define OCN_LBUTTONDOWN	(OCN_BASE+WM_LBUTTONDOWN)
#define OCN_MOUSEMOVE			(OCN_BASE+WM_MOUSEMOVE)
#define OCN_LBUTTONUP			(OCN_BASE+WM_LBUTTONUP)
#define OCN_RBUTTONUP			(OCN_BASE+WM_RBUTTONUP)
#define OCN_KEYDOWN				(OCN_BASE+WM_KEYDOWN)
#define OCN_CHAR						(OCN_BASE+WM_CHAR)

#define OCN_GETCELLTEXT		(NM_FIRST+10)
#define OCN_SETCELLTEXT		(NM_FIRST+13)
#define OCN_DRAWCELL		(NM_FIRST+17)
#define OCN_ROWSINSERTFRONT	(NM_FIRST+19)
#define OCN_DELETEROWS		(NM_FIRST+20)
#define OCN_COLSINSERTFRONT	(NM_FIRST+21)
#define OCN_DELETECOLS		(NM_FIRST+22)
#define OCN_SETROWS			(NM_FIRST+23)
#define OCN_SETCOLS			(NM_FIRST+24)
#define OCN_ROWSHEIGHTSCHANGE	(NM_FIRST+25)
#define OCN_COLSWIDTHSCHANGE	(NM_FIRST+26)
#define OCN_ACTIVECELLCHANGE	(NM_FIRST+27)
#define OCN_SELECTION_DRAG_END	(NM_FIRST+28)
#define OCN_ENDCELLEDIT     LVN_ENDLABELEDIT     // LVN_FIRST-6
#define OCN_DRAWHEADCELL	(NM_FIRST+29)

namespace mycell{
	//static const OCN_GETCELLTEXT = NM_FIRST+10;
	//static const OCN_SETCELLTEXT = NM_FIRST+13;
	//static const OCN_RBUTTONDOWN = NM_FIRST+15;
	//static const OCN_DRAWCELL	 = NM_FIRST+17;

	typedef struct tagDrawTextStruct{
		//HDC hDC;
		//LPCRECT lprcCell;
		UINT uDrawTextFormat;//DrawText��uFormat����
		LPCTSTR lpszCellText;
		int nTextLen;
	}DrawTextStruct1;
	/*
	
	typedef struct tagDrawCellStruct{
		HDC hDC;
		BYTE	nCellType;	//ECellType
		COLORREF bkclr;
		DrawTextStruct* pDTS;//can be null if there is not text to draw
		RECT fillRect;//bound of the cell
		RECT textRect;//bound of the text 
		UINT hAlignment;
		UINT vAlignment;
		int activeRow;//
		int activeCol;//
		bool fMergeCell;	//�Ƿ�ϲ���Ԫ��
		//ECellBGShrinkState* peShrink;
	}DrawCellStruct;
	*/

	enum HeaderType
	{
		MHT_HEADER_CORNER,
		MHT_ROW_HEADER,
		MHT_COL_HEADER,
	};
	/*
	enum HeaderSelectionType
	{
		MHST_NOT_IN_SELECTION,			//����ѡ����
		MHST_IN_SELECTION,		//��ѡ����
		MHST_IN_PROJECTION_OF_SELECTION,//��ѡ�񼯵�ͶӰ����
	};

	typedef struct tagDrawHeaderCellStruct{
		HDC hDC;
		COLORREF bkclr;
		DrawTextStruct1* pDTS;//can be null if there is not text to draw
		RECT fillRect;//bound of the cell
		int activeRow;//
		int activeCol;//
		HeaderType headerType;
		ESelectionState selType;
		//BOOL bRowHeader;
		//BOOL bHeaderCorner;
		//BOOL bInSelection;
		//BOOL bFullInSelection;
		BOOL bHandled;
	}DrawHeaderCellStruct;
	*/

	/*
	typedef struct tagHitTestStruct
	{
		POINT pt;
		ECellHitTestConstants hit;
		CCell cell;
	}HitTestStruct;
	*/
	typedef struct tagCELLHITTESTINFO {
		POINT pt;	//Position to hit test, in client coordinates. 
		UINT flags;	//Variable that receives the results of a hit test. The control sets this member to one of the values of  ECellHitTestConstants
		CCell cell;	//Variable that receives the row and col results of a hit test.
	} CELLHITTESTINFO, *LPCELLHITTESTINFO;

	struct KeyDownInfo
	{
		WPARAM& wParam;
		LPARAM& lParam;
		KeyDownInfo(WPARAM w,LPARAM l):wParam(w),lParam(l)
		{}
	};
	//struct GetCellTextInfo
	//{
	//	LPTSTR lpText;
	//	bool bRender;//�Ƿ����ڻ��ƻ�tooltip
	//	//GetCellTextInfo(LPTSTR buf,bool bRen):lpText
	//};
	/*
	// This structure sent to Grid's listener in a WM_NOTIFY message
	typedef struct tagNM_GRIDVIEW {
		NMHDR hdr;
		int   row;
		int   col;
		LPARAM lParam;
		HRESULT hr;
		BOOL bHandled;
	} NM_SHEETVIEW;
	*/

	typedef struct tagSelectionDragEndStruct{
		bool bExpand;//true-����,false��С
		bool bHorz;//ˮƽ�����������С��
		RECT oldSelection;//RECT�д�ĵ�Ԫ��������������ڴ����ϵ�λ��
		RECT newSelection;//
		RECT expand;//��������IJ���
	}SelectionDragEndStruct;
}

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
Web Developer
China China
My name is Yanxueming,i live in Chengdu China.Graduated from UESTC in 1999.

Comments and Discussions