Click here to Skip to main content
15,895,746 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 91K   4.5K   81  
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.
#pragma once
//----------------------------------------------------------------------------//
//�����㷨��
//----------------------------------------------------------------------------//
namespace mycell{
		//����lprc1,lprc2�Ƿ��ڽ�
	inline BOOL rect_adjoin(LPCRECT lprc1,LPCRECT lprc2)
	{
		return (lprc1->right==lprc2->left || lprc1->left==lprc2->right)
			&& lprc1->bottom>=lprc2->top 
			&& lprc1->top<=lprc2->bottom
			|| (lprc1->bottom==lprc2->top || lprc1->top==lprc2->bottom)
			&& lprc1->right>=lprc2->left
			&& lprc1->left<=lprc2->right;
	}
	//�������Ƿ����
	inline BOOL rect_equal(LPCRECT lprc1,LPCRECT lprc2)
	{
		return lprc1->left==lprc2->left
			&& lprc1->right==lprc2->right
			&& lprc1->top==lprc2->top
			&& lprc1->bottom==lprc2->bottom;
	}
	//�������Ƿ����루û���ص����֣�
	inline BOOL rect_disjoin(LPCRECT lprc1,LPCRECT lprc2)
	{
		return lprc1->left > lprc2->right
			|| lprc1->right< lprc2->left
			|| lprc1->top > lprc2->bottom
			|| lprc1->bottom<lprc2->top;
	}

	//����lprc1�Ƿ���lprc2���ڲ�
	inline BOOL rect_internal(LPCRECT lprc1,LPCRECT lprc2)
	{
		return lprc1->left>=lprc2->left && lprc1->right<=lprc2->right
			&& lprc1->top>=lprc2->top && lprc1->bottom<=lprc2->bottom;
	}
	//����lprc1�Ƿ����lprc2
	inline BOOL rect_contain(LPCRECT lprc1,LPCRECT lprc2)
	{
		return rect_internal(lprc2,lprc1);
		//return lprc1->left<=lprc2->left && lprc1->right>=lprc2->right
		//	&& lprc1->top<=lprc2->top && lprc1->bottom>=lprc2->bottom;
	}
	//��Կ�����ཻ���п�������RRS_EUQAL,RRS_CONTAIN,RRS_INTERNAL
	inline BOOL intersect(LPCRECT lprc1,LPCRECT lprc2)
	{
		return !(
		lprc1->left >= lprc2->right 
			|| lprc1->right <= lprc2->left
			|| lprc1->top >= lprc2->bottom
			|| lprc1->bottom <= lprc2->top);
	}
	inline eRectRelationShip get_RectRelationShip(LPCRECT lprc1,LPCRECT lprc2)
	{
		if(rect_equal(lprc1,lprc2))
			return RRS_EQUAL;
		if(rect_disjoin(lprc1,lprc2))
			return RRS_DISJOIN;
		if(rect_internal(lprc1,lprc2))
			return RRS_INTERNAL;
		if(rect_contain(lprc1,lprc2))
			return RRS_CONTAIN;
		return RRS_INTERSECT;
	}
}//namespace mycell

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