- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
Filler.cpp
资源名称:strategy.zip [点击查看]
上传用户:xrc9201
上传日期:2013-02-04
资源大小:35k
文件大小:5k
源码类别:
源码/资料
开发平台:
Visual C++
- #include "Stdafx.h"
- #include "Filler.h"
- // CFiller - Implementation
- CFiller::CFiller()
- {
- m_csText = _T("");
- m_nMinVal = 0;
- m_nMaxVal = 100;
- m_nPos = 0;
- m_FillerColor = RGB( 0, 0, 255 );
- m_FillerBkColor = RGB( 255, 0, 0 );
- m_FillerTextColor = RGB( 255, 255, 255 );
- }
- CFiller::~CFiller()
- {
- }
- INT CFiller::SetFillerText( LPCSTR lpszText )
- {
- // Step 1 - Set Filler Text
- m_csText = lpszText;
- return SUCCESS;
- }
- INT CFiller::SetFillerRange( INT nMinVal, INT nMaxVal )
- {
- // Step 1 - Set MinVal and MaxVal after validating
- if( nMaxVal <= nMinVal )
- {
- return FAILURE;
- }
- m_nMinVal = nMinVal;
- m_nMaxVal = nMaxVal;
- return SUCCESS;
- }
- INT CFiller::GetFillerPos()
- {
- // Step 1 - Return m_nPos
- return m_nPos;
- }
- INT CFiller::SetFillerPos( INT nPos )
- {
- // Step 1 - Validate pos before setting
- if( nPos < m_nMinVal || nPos > m_nMaxVal )
- {
- return FAILURE;
- }
- // Step 2 - Store old filler pos
- INT nOldPos = m_nPos;
- // Step 3 - Set m_nPos
- m_nPos = nPos;
- // Step 4 - Return old filler pos
- return nOldPos;
- }
- COLORREF CFiller::SetFillerColor( COLORREF & rFillerColor )
- {
- // Step 1 - Store old color
- COLORREF OldFillerColor = m_FillerColor;
- // Step 2 - Set m_FillerColor
- m_FillerColor = rFillerColor;
- // Step 3 - Return old filler color
- return OldFillerColor;
- }
- COLORREF CFiller::SetFillerBkColor( COLORREF & rFillerBkColor )
- {
- // Step 1 - Store old bk color
- COLORREF OldFillerBkColor = m_FillerBkColor;
- // Step 2 - Set m_FillerBkColor
- m_FillerBkColor = rFillerBkColor;
- // Step 3 - Return old filler bk color
- return OldFillerBkColor;
- }
- COLORREF CFiller::SetFillerTextColor( COLORREF & rFillerTextColor )
- {
- // Step 1 - Store old text color
- COLORREF OldFillerTextColor = m_FillerTextColor;
- // Step 2 - Set m_FillerTextColor
- m_FillerTextColor = rFillerTextColor;
- // Step 3 - Return old filler text color
- return OldFillerTextColor;
- }
- // CLtoRFiller - Implementation
- CLToRFiller::CLToRFiller() : CFiller()
- {
- }
- CLToRFiller::~CLToRFiller()
- {
- }
- INT CLToRFiller::DoFill( CWnd * pWnd, const CRect & rRect )
- {
- CRect Rect = rRect;
- // Step 1 - Validate window pointer
- ASSERT( IsWindow( pWnd->m_hWnd ) );
- // Step 2 - Calculate Fill Area
- INT nRight = 0;
- nRight = ( rRect.Width() * m_nPos ) / ( m_nMaxVal - m_nMinVal );
- CRect FillArea( rRect.left, rRect.top, nRight, rRect.bottom );
- CRect RemainingArea( nRight, rRect.top, rRect.right, rRect.bottom );
- CDC * pDC = pWnd->GetDC();
- pDC->FillSolidRect( FillArea, m_FillerColor );
- pDC->FillSolidRect( RemainingArea, m_FillerBkColor );
- // Step 3 - Display text provided or the default %
- if( m_csText.IsEmpty() == FALSE )
- {
- pDC->SetBkMode( TRANSPARENT );
- pDC->SetTextColor( m_FillerTextColor );
- pDC->DrawText( m_csText, m_csText.GetLength(),
- Rect, DT_CENTER | DT_WORDBREAK | DT_VCENTER | DT_SINGLELINE );
- }
- else if( m_nPos > 0 )
- {
- CHAR szText[ 512 ];
- memset( szText, 0, sizeof( szText ) );
- INT nPercent = ( INT )( ( ( double ) m_nPos / ( double ) m_nMaxVal ) * 100 );
- sprintf( szText, "%d%%", nPercent );
- pDC->SetBkMode( TRANSPARENT );
- pDC->SetTextColor( m_FillerTextColor );
- pDC->DrawText( szText, strlen( szText ),
- Rect, DT_CENTER | DT_WORDBREAK | DT_VCENTER | DT_SINGLELINE );
- }
- pWnd->ReleaseDC( pDC );
- return SUCCESS;
- }
- // CRToLFiller - Implementation
- CRToLFiller::CRToLFiller() : CFiller()
- {
- }
- CRToLFiller::~CRToLFiller()
- {
- }
- INT CRToLFiller::DoFill( CWnd * pWnd, const CRect & rRect )
- {
- CRect Rect = rRect;
- // Step 1 - Validate window pointer
- ASSERT( IsWindow( pWnd->m_hWnd ) );
- // Step 2 - Calculate Fill Area
- INT nLeft = 0;
- nLeft = ( rRect.Width() * m_nPos ) / ( m_nMaxVal - m_nMinVal );
- nLeft = rRect.Width() - nLeft;
- CRect FillArea( nLeft, rRect.top, rRect.right, rRect.bottom );
- CRect RemainingArea( rRect.left, rRect.top, nLeft, rRect.bottom );
- CDC * pDC = pWnd->GetDC();
- pDC->FillSolidRect( FillArea, m_FillerColor );
- pDC->FillSolidRect( RemainingArea, m_FillerBkColor );
- // Step 3 - Display text provided or the default %
- if( m_csText.IsEmpty() == FALSE )
- {
- pDC->SetBkMode( TRANSPARENT );
- pDC->SetTextColor( m_FillerTextColor );
- pDC->DrawText( m_csText, m_csText.GetLength(),
- Rect, DT_CENTER | DT_WORDBREAK | DT_VCENTER | DT_SINGLELINE );
- }
- else if( m_nPos > 0 )
- {
- CHAR szText[ 512 ];
- memset( szText, 0, sizeof( szText ) );
- INT nPercent = ( INT )( ( ( double ) m_nPos / ( double ) m_nMaxVal ) * 100 );
- sprintf( szText, "%d%%", nPercent );
- pDC->SetBkMode( TRANSPARENT );
- pDC->SetTextColor( m_FillerTextColor );
- pDC->DrawText( szText, strlen( szText ),
- Rect, DT_CENTER | DT_WORDBREAK | DT_VCENTER | DT_SINGLELINE );
- }
- pWnd->ReleaseDC( pDC );
- return SUCCESS;
- }