Click here to Skip to main content
15,893,266 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.
/* -------------------------------------------------------------------------
//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
//Yanxm 2008��1��26�� 15:28:29
// -----------------------------------------------------------------------*/
#pragma once
class DeleteGdiObjPolicy
{
protected:
	void DelGdiObject(HGDIOBJ obj)
	{
		DeleteObject(obj);
	}
};
class DeleteGdiObjDummyPolicy
{
protected:
	void DelGdiObject(HGDIOBJ obj)
	{
	}
};
template<class GdiObjDelPolicy=DeleteGdiObjPolicy>
class GdiSelectObject : public GdiObjDelPolicy
{
	HDC hDC_;
	HGDIOBJ	 oldObj_;
public:
	GdiSelectObject(HDC hDC,HGDIOBJ hObj):hDC_(hDC)
	{
		oldObj_=::SelectObject(hDC,hObj);
	}
	void SelectObject(HGDIOBJ hObj)
	{
		GdiObjDelPolicy::DelGdiObject(::SelectObject(hDC_,oldObj_));
		oldObj_=::SelectObject(hDC_,hObj);
	}
	~GdiSelectObject()
	{
		GdiObjDelPolicy::DelGdiObject(::SelectObject(hDC_,oldObj_));
	}
};
typedef GdiSelectObject<DeleteGdiObjDummyPolicy> GdiSelectObjectPlain;
typedef GdiSelectObject<> GdiSelectObjectAutoDel;
class GDISetROP2
{
	HDC hDC_;
	int fnDrawMode_;
public:
	GDISetROP2(HDC hdc,int fnDrawMode):hDC_(hdc)
	{
		fnDrawMode_=SetROP2(hDC_,fnDrawMode);
	}
	~GDISetROP2()
	{
		SetROP2(hDC_,fnDrawMode_);
	}
};

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