⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colourpickercb.cpp

📁 电子白板程序
💻 CPP
字号:
// ColourPickerCB.cpp
//
// Copyright (C)2000 Mark Jackson
//   e-mail: mark@mjsoft.co.uk
// web-site: http://www.mjsoft.co.uk
//
// based on the control by James R. Twine.

#include "stdafx.h"
#include "ColourPickerCB.h"

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

COLORREF colors[] = 
{
	RGB( 000 , 000 , 000 ),//黑色
	RGB( 255 , 255 , 255 ),//白色
	RGB( 128 , 128 , 128 ),
	RGB( 192 , 192 , 192 ),
	RGB( 128 , 000 , 000 ),
	RGB( 255 , 000 , 000 ),
	RGB( 128 , 128 , 000 ),
	RGB( 255 , 255 , 000 ),
	RGB( 000 , 128 , 000 ),
	RGB( 000 , 255 , 000 ),
	RGB( 000 , 128 , 128 ),
	RGB( 000 , 255 , 255 ),
	RGB( 000 , 000 , 128 ),
	RGB( 000 , 000 , 255 ),
	RGB( 128 , 000 , 128 ),
	RGB( 255 , 000 , 255 ),
	RGB( 128 , 128 , 064 ),
	RGB( 255 , 255 , 128 ),
	RGB( 000 , 064 , 064 ),
	RGB( 000 , 255 , 128 ),
	RGB( 000 , 128 , 255 ),
	RGB( 128 , 255 , 255 ),
	RGB( 000 , 064 , 128 ),
	RGB( 128 , 128 , 255 ),
	RGB( 064 , 000 , 255 ),
	RGB( 255 , 000 , 128 ),
	RGB( 128 , 064 , 000 ),
	RGB( 255 , 128 , 064 ),
};

CColourPickerCB::CColourPickerCB()
{
	this->SetMode( COLOR );
}

CColourPickerCB::~CColourPickerCB()
{
}

void DDX_ColourPickerCB( CDataExchange *pDX, int nIDC, int& value )
{
	HWND hWndCtrl = pDX->PrepareCtrl( nIDC );
	ASSERT( hWndCtrl );

	CColourPickerCB *pPicker = (CColourPickerCB*)CWnd::FromHandle( hWndCtrl );
	ASSERT( pPicker );

	// only support getting of colour.
	if( pDX->m_bSaveAndValidate )
	{
		value = pPicker->GetSelectedValue();
	}
}


BEGIN_MESSAGE_MAP(CColourPickerCB, CComboBox)
	//{{AFX_MSG_MAP(CColourPickerCB)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColourPickerCB message handlers

BOOL CColourPickerCB::PreCreateWindow(CREATESTRUCT& cs) 
{
	cs.style |= CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | CBS_HASSTRINGS;

	return CComboBox::PreCreateWindow(cs);
}

int CColourPickerCB::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CComboBox::OnCreate(lpCreateStruct) == -1)
		return -1;

	if( this->m_mode == COLOR )
	{
		for( int i = 0; i < sizeof( colors ) / sizeof( COLORREF ); i ++ )
			
			this->AddValue( colors[ i ] );
	}
	else if( this->m_mode == LINE )
	{
		for( int i = 1; i < 10; i ++ )

			this->AddValue( i );
	}
	if( this->GetCount() )
		
		this->SetCurSel( 0 );
	
	return 0;
}

void CColourPickerCB::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{	
}

void CColourPickerCB::DrawItem( LPDRAWITEMSTRUCT pDIStruct )
{
	CDC dcContext;

	CRect rItemRect( pDIStruct->rcItem );

	CRect rBlockRect( rItemRect );

	CBrush brFrameBrush;

	if( !dcContext.Attach( pDIStruct->hDC ) )
	{
		return;
	}
	brFrameBrush.CreateStockObject( BLACK_BRUSH );

	if( pDIStruct->itemState & ODS_SELECTED )
	{
		dcContext.FillSolidRect( &rBlockRect, GetSysColor( COLOR_HIGHLIGHT ) );
	}
	else
	{
		dcContext.FillSolidRect( &rBlockRect, GetSysColor( COLOR_WINDOW ) );
	}
	if( pDIStruct->itemState & ODS_FOCUS )
	{
		dcContext.DrawFocusRect( &rItemRect );
	}
	rBlockRect.DeflateRect( CSize( 2, 2 ) );
	
	if( pDIStruct->itemID != -1 )
	{
		if( this->m_mode == COLOR )
		{
			COLORREF color;

			if( pDIStruct->itemState & ODS_DISABLED )
			{
				color = GetSysColor( COLOR_INACTIVECAPTIONTEXT );
			}
			else
			{
				color = GetItemData( pDIStruct->itemID );
			}
			dcContext.FillSolidRect( &rBlockRect, color );
			
			dcContext.FrameRect( &rBlockRect, &brFrameBrush );
		}
		else if( this->m_mode == LINE )
		{
			int width = GetItemData( pDIStruct->itemID );

			CPen pen( PS_SOLID , width , pDIStruct->itemState & ODS_SELECTED ? RGB( 128 , 128 , 128 ) : RGB( 0 , 0 , 0 ) );

			dcContext.SelectObject( &pen );

			int center = ( rBlockRect.bottom + rBlockRect.top ) / 2;

			dcContext.MoveTo( CPoint( rBlockRect.left , center ) );

			dcContext.LineTo( CPoint( rBlockRect.right , center ) );
		}
	}
	dcContext.Detach();
}

int CColourPickerCB::GetSelectedValue()
{
	return GetItemData( GetCurSel() );
}

void CColourPickerCB::AddValue( int value )
{
	int iIndex = AddString( "" );

	if( iIndex >= 0 )

		SetItemData( iIndex, value );
}

⌨️ 快捷键说明

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