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

📄 progind.cpp

📁 在C++程序中使用Strategy模板
💻 CPP
字号:
// ProgInd.cpp : implementation file
//

#include "stdafx.h"
#include "ProgInd.h"
#include "Filler.h"

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

/////////////////////////////////////////////////////////////////////////////
// CProgressIndicator

CProgressIndicator::CProgressIndicator( CFiller * pFiller ) : m_pFiller( pFiller )
{
	// Step 1 - Set m_bCreated to FALSE
	m_bCreated = FALSE;
	// Step 2 - Check and create m_pFiller
	if( m_pFiller == NULL )
	{
		m_pFiller  = new CLToRFiller;	
		m_bCreated = TRUE;
	}
	// Step 3 - Validate m_pFiller
	ASSERT( m_pFiller != NULL );
}

CProgressIndicator::~CProgressIndicator()
{
	// Step 1 - Check and delete m_pFiller
	if( m_bCreated == TRUE )
	{
		delete m_pFiller;
	}
}


BEGIN_MESSAGE_MAP(CProgressIndicator, CWnd)
	//{{AFX_MSG_MAP(CProgressIndicator)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProgressIndicator methods

CFiller * CProgressIndicator::GetFiller()
{
	// Step 1 - Return m_pFiller
	return m_pFiller;
}

INT CProgressIndicator::SetFiller( CFiller * pFiller )
{
	// Step 1 - Validate pFiller
	ASSERT( pFiller != NULL );
	// Step 2 - Check and delete m_pFiller
	if( m_bCreated == TRUE )
	{
		delete m_pFiller;
		m_bCreated = FALSE;
	}
	// Step 3 - Set m_pFiller to the parameter passed
	m_pFiller = pFiller;
	return SUCCESS;
}

INT CProgressIndicator::SetText( LPCSTR lpszText )
{
	// Step 1 - Delegate and forward this to CFiller object
	INT nRetVal = m_pFiller->SetFillerText( lpszText );
	Invalidate();
	return nRetVal;
}

INT CProgressIndicator::SetRange( INT nMinRange, INT nMaxRange )
{
	// Step 1 - Delegate and forward this to CFiller object
	return m_pFiller->SetFillerRange( nMinRange, nMaxRange );
}

INT CProgressIndicator::GetPos()
{
	// Step 1 - Delegate and forward this to CFiller object
	return m_pFiller->GetFillerPos();
}

INT CProgressIndicator::SetPos( INT nPos )
{
	// Step 1 - Delegate and forward this to CFiller object
	INT nOldPos = m_pFiller->SetFillerPos( nPos );
	Invalidate();
	return nOldPos;
}

/////////////////////////////////////////////////////////////////////////////
// CProgressIndicator message handlers

void CProgressIndicator::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// Step 1 - Get the client Rectangle
	CRect Rect;
	GetClientRect( & Rect );
	// Step 2 - Call DoFill to do the filling, based on the current situation
	m_pFiller->DoFill( this, Rect );
}

⌨️ 快捷键说明

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