formitemcheck.cpp

来自「基于WINDOWS mobile 的用于创建一个窗体和自定义试图的工程」· C++ 代码 · 共 115 行

CPP
115
字号
// FormItemCheck.cpp: implementation of the CFormItemCheck class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FormItemCheck.h"
#include "FormListCtrl.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

using namespace DRA;


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


CFormItemCheck::CFormItemCheck()
:	m_nVal		(0)
{

}


CFormItemCheck::~CFormItemCheck()
{

}


// CFormItemCheck::DrawCheck
//
//		Draws the check mark
//
void CFormItemCheck::DrawCheck(HDC hDC, int x, int y)
{
	POINT	pt[3] = { { x + SCALEX( 3), y + SCALEY(6) }, 
					  { x + SCALEX( 6), y + SCALEY(9) }, 
					  { x + SCALEX(12), y + SCALEY(3) } };

	DRA::Polyline(hDC, pt, 3, PS_DOWNRIGHT);

	++pt[0].y;
	++pt[1].y;
	++pt[2].y;
	DRA::Polyline(hDC, pt, 3, PS_DOWNRIGHT);

	++pt[0].y;
	++pt[1].y;
	++pt[2].y;
	DRA::Polyline(hDC, pt, 3, PS_DOWNRIGHT);
}


// CFormItemCheck::CustomDraw
//
//		Draws check control
//
LRESULT CFormItemCheck::CustomDraw(CFormListCtrl* pForm, NMLVCUSTOMDRAW *pLVCD)
{
	DWORD	dwDrawStage = pLVCD->nmcd.dwDrawStage;
	LRESULT	lRet		= CDRF_SKIPDEFAULT;

	if(dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
	{
		if(pLVCD->iSubItem == 1)
		{
			HDC		hDC			= pLVCD->nmcd.hdc;
			RECT	rc			= pLVCD->nmcd.rc;
			HBRUSH	hWhiteBrush	= (HBRUSH)GetStockObject(WHITE_BRUSH),
					hOldBrush;

			hOldBrush = (HBRUSH)::SelectObject(hDC, hWhiteBrush);
			
			DRA::Rectangle(hDC, rc.left + SCALEX(4), rc.top + SCALEY(1), rc.left + SCALEX(19), rc.top + SCALEY(16));
			if(m_nVal)
				DrawCheck(hDC, rc.left + SCALEX(4), rc.top + SCALEY(1));
			
			if(m_dwFlags & FIF_LINE)
				DrawBottomLine(pLVCD);

			DrawFocus(hDC, &pLVCD->nmcd.rc);

			::SelectObject(hDC, hOldBrush);
		}
		else
		{
			//
			// Use default painter
			//
			lRet = CFormItem::CustomDraw(pForm, pLVCD);
		}
	}
	return lRet;
}


// CFormItemCheck::ShowEditor
//
//		Shows the editor - Effectively toggles the state
//
BOOL CFormItemCheck::ShowEditor(CFormListCtrl* pForm, BOOL /*bShow*/, int iItem, int /*iSubItem*/)
{
	m_nVal = !m_nVal;

	pForm->RedrawItems(iItem, iItem);
	pForm->ItemUpdated(this, 0);
	return FALSE;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?