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

📄 colorpic.cpp

📁 电力监控系统 实时告警处理程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void	CColorPickerCB::DrawItem( LPDRAWITEMSTRUCT pDIStruct )
{
	COLORREF	crColor = 0;
	COLORREF	crNormal = GetSysColor( COLOR_WINDOW );
	COLORREF	crSelected = GetSysColor( COLOR_HIGHLIGHT );
	COLORREF	crText = GetSysColor( COLOR_WINDOWTEXT );
	CBrush		brFrameBrush;
	TCHAR		cColor[ CCB_MAX_COLOR_NAME ];				// Color Name Buffer
	CRect		rItemRect( pDIStruct -> rcItem );
	CRect		rBlockRect( rItemRect );
	CRect		rTextRect( rBlockRect );
	CDC			dcContext;
	int			iFourthWidth = 0;
	int			iItem = pDIStruct -> itemID;
	int			iState = pDIStruct -> itemState;

	if( !dcContext.Attach( pDIStruct -> hDC ) )				// Attach CDC Object
	{
		return;												// Stop If Attach Failed
	}
	iFourthWidth = ( rBlockRect.Width());//* / 4 );				//jyy masked to lost 文字 Get 1/4 Of Item Area
	brFrameBrush.CreateStockObject( BLACK_BRUSH );			// Create Black Brush

	if( iState & ODS_SELECTED )								// If Selected
	{														// Set Selected Attributes
		dcContext.SetTextColor( ( 0x00FFFFFF & ~( 
				crText ) ) );								// Set Inverted Text Color (With Mask)
		dcContext.SetBkColor( crSelected );					// Set BG To Highlight Color
		dcContext.FillSolidRect( &rBlockRect, crSelected );	// Erase Item
	}
	else													// If Not Selected
	{														// Set Standard Attributes
		dcContext.SetTextColor( crText );					// Set Text Color
		dcContext.SetBkColor( crNormal );					// Set BG Color
		dcContext.FillSolidRect( &rBlockRect, crNormal );	// Erase Item
	}
	if( iState & ODS_FOCUS )								// If Item Has The Focus
	{
		dcContext.DrawFocusRect( &rItemRect );				// Draw Focus Rect
	}
	//
	//	Calculate Text Area...
	//
	rTextRect.left += ( iFourthWidth + 2 );					// Set Start Of Text
	rTextRect.top += 2;										// Offset A Bit

	//
	//	Calculate Color Block Area..
	//
	rBlockRect.DeflateRect( CSize( 2, 2 ) );				// Reduce Color Block Size
	rBlockRect.right = iFourthWidth;						// Set Width Of Color Block

	//
	//	Draw Color Text And Block...
	//
	if( iItem != -1 )										// If Not An Empty Item
	{
		int		iChars = GetLBText( iItem, cColor );		// Get Color Text
		int		iaTabStops[ 1 ] = { 50 };

		_ASSERTE( iChars != LB_ERR );						// Sanity Check

		if( iState & ODS_DISABLED )							// If Disabled
		{
			crColor = ::GetSysColor( COLOR_GRAYTEXT );		// Get Inactive Text Color
			dcContext.SetTextColor( crColor );				// Set Text Color
		}
		else												// If Normal
		{
			crColor = GetItemData( iItem );					// Get Color Value
		}
		dcContext.SetBkMode( TRANSPARENT );					// Transparent Background
		dcContext.TabbedTextOut( rTextRect.left, 
				rTextRect.top, cColor, iChars, 1, 
				iaTabStops, 0 );							// Draw Color Name

		dcContext.FillSolidRect( &rBlockRect, crColor );	// Draw Color
				
		dcContext.FrameRect( &rBlockRect, &brFrameBrush );	// Draw Frame
	}
	dcContext.Detach();										// Detach DC From Object
	
	return;													// Done!
}


COLORREF	CColorPickerCB::GetSelectedColorValue( void )
{
	int		iSelectedItem = GetCurSel();					// Get Selected Item

	if( iSelectedItem == CB_ERR )							// If Nothing Selected
	{
		return( RGB( 0, 0, 0 ) );							// Return Black
	}
	return( GetItemData( iSelectedItem ) );					// Return Selected Color
}


LPCTSTR	CColorPickerCB::GetSelectedColorName( void )
{
	int		iSelectedItem = GetCurSel();					// Get Selected Item

	if( iSelectedItem != CB_ERR )							// If Something Selected
	{
		GetLBText( iSelectedItem, m_cColorName );			// Store Name Of Color
	}
	else													// If Nothing Selected
	{
		m_cColorName[ 0 ] = _T( '\0' );						// Terminate Color Name Buffer (Zero Length String)
	}
	return( m_cColorName );									// Return Selected Color Name
}


void CColorPickerCB::SetSelectedColorValue( COLORREF crClr )
{
	int		iItems = GetCount();
	
	for( int iItem = 0; iItem < iItems; iItem++ )
	{
		if( crClr == GetItemData( iItem ) )					// If Match Found
		{
			SetCurSel( iItem );								// Select It
			break;											// Stop Looping
		}
	}
	return;													// Done!
}


void	CColorPickerCB::SetSelectedColorName( LPCTSTR cpColor )
{
	int		iItems = GetCount();
	TCHAR	cColor[ CCB_MAX_COLOR_NAME ];

	for( int iItem = 0; iItem < iItems; iItem++ )
	{
		GetLBText( iItem, cColor );							// Get Color Name
		if( !_tcsicmp( cColor, cpColor ) )					// If Match Found
		{
			SetCurSel( iItem );								// Select It
			break;											// Stop Looping
		}
	}
	return;													// Done!
}


int		CColorPickerCB::AddColor( LPCTSTR cpColor, COLORREF crColor )
{
	int		iIndex = CB_ERR;

	_ASSERTE( cpColor );									// Need This!

#if	defined( _INCLUDE_COLOR_INFO )
	TCHAR	caColor[ 256 ];

	_ASSERTE( _stprintf( caColor, 
			_T( "%s\t\t%02X%02X%02X" ), cpColor, GetRValue( 
				crColor ), GetGValue( crColor ), GetBValue( 
				crColor ) ) < 255 );						// Build The Debug String
		iIndex = AddString(	caColor );						// Set Color Name/Text
#else
		iIndex = AddString(	cpColor );						// Insert Just The Color
#endif
	if( iIndex != CB_ERR )									// If Inserted
	{
		SetItemData( iIndex, (DWORD)crColor );				// Set The Color Value
	}
	return( iIndex );										// Return Insertion Locatiom Or Failure Code
}


bool	CColorPickerCB::RemoveColor( LPCTSTR cpColor )
{
	TCHAR	cColor[ CCB_MAX_COLOR_NAME ];
	bool	bRemoved = false;
	int		iItems = GetCount();

	for( int iItem = 0; iItem < iItems; iItem++ )
	{
		GetLBText( iItem, cColor );							// Get Color Name
		if( !_tcsicmp( cColor, cpColor ) )					// If Match Found
		{
			if( DeleteString( iItem ) != CB_ERR )			// Remove It
			{
				bRemoved = true;							// Set Flag If Removed
				break;										// Stop Checking
			}
		}
	}
	return( bRemoved );										// Done!
}


bool	CColorPickerCB::RemoveColor( COLORREF crClr )
{
	bool	bRemoved = false;
	int		iItems = GetCount();

	for( int iItem = 0; iItem < iItems; iItem++ )
	{
		if( crClr == GetItemData( iItem ) )					// If Desired Color Found
		{
			if( DeleteString( iItem ) != CB_ERR )			// Remove It
			{
				bRemoved = true;							// Set Flag If Removed
				break;										// Stop Checking
			}
		}
	}
	return( bRemoved );										// Done!
}


void	CColorPickerCB::DDX_ColorPicker( CDataExchange *pDX, int iIDC, COLORREF &crColor )
{
	CColorPickerCB	*pPicker = NULL;
	HWND			hWndCtrl = pDX -> PrepareCtrl( iIDC );
	
	_ASSERTE( hWndCtrl );									// (In)Sanity Check

	pPicker = (CColorPickerCB*)CWnd::FromHandle( hWndCtrl );// Get Actual Control
	
	_ASSERTE( pPicker );									// (In)Sanity Check

	if( !( pDX -> m_bSaveAndValidate ) )					// If Setting The Color Value
	{
		pPicker -> SetSelectedColorValue( crColor );		// Set It
	}
	else													// If Getting The Color Value
	{
		crColor = pPicker -> GetSelectedColorValue();		// Get It
	}
	return;													// Done!
}


void	CColorPickerCB::DDX_ColorPicker( CDataExchange *pDX, int iIDC, CString &sName )
{
	CColorPickerCB	*pPicker = NULL;
	HWND			hWndCtrl = pDX -> PrepareCtrl( iIDC );
	
	_ASSERTE( hWndCtrl );									// (In)Sanity Check

	pPicker = (CColorPickerCB*)CWnd::FromHandle( hWndCtrl );// Get Actual Control
	
	_ASSERTE( pPicker );									// (In)Sanity Check

	if( !( pDX -> m_bSaveAndValidate ) )					// If Setting The Color Name
	{
		pPicker -> SetSelectedColorName( sName );			// Set It
	}
	else													// If Getting The Color Name
	{
		sName = pPicker -> GetSelectedColorName();			// Get It
	}
	return;													// Done!
}


#pragma warning (disable : 4018)	// '<':  signed/unsigned mismatch
#pragma warning (disable : 4100)	// unreferenced formal parameter
#pragma warning (disable : 4127)	// conditional expression is constant
#pragma warning (disable : 4244)	// conv from X to Y, possible loss of data
#pragma warning (disable : 4310)	// cast truncates constant value
#pragma warning (disable : 4505)	// X: unreference local function removed
#pragma warning (disable : 4510)	// X: default ctor could not be generated
#pragma warning (disable : 4511)	// X: copy constructor could not be generated
#pragma warning (disable : 4512)	// assignment operator could not be generated
#pragma warning (disable : 4514)	// debug symbol exceeds 255 chars
#pragma warning (disable : 4610)	// union X can never be instantiated
#pragma warning (disable : 4663)	// to explicitly spec class template X use ...
#pragma warning (disable : 4710)	// function 'XXX' not expanded
#pragma	warning	(disable : 4786)	// X: identifier truncated to '255' chars


⌨️ 快捷键说明

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