ATL彩色渐变进度条控件

翻译|其它|编辑:郝浩|2004-01-20 11:24:00.000|阅读 1880 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

开发环境: VC6.0, Windows2000 Pro.

测试环境: Windows2000 Pro,192M,6GHD,PIII 550

讲解:

ATLProcessCtrl——ProcessCtrl
1、Properties
	1) 进度条显示的最大值
	   short ProcessRange;			(put only)
	2) 是否显示进度百分比数字
	   short ShowProcessNumber;		(put only)
	3) 文本颜色
	   long TextForeColor;			(get/put)
	4) 文本背景颜色
	   long TextBackgroundColor;	(get/put)
	5) 渐变开始颜色
	   long ShadowBeginColor;		(get/put)
	6)渐变结束颜色
	   long ShadowEndColor;			(get/put)
	   
2、Methods
	1) 显示进度
	    HRESULT ShowProcess(long nCurrentValue);
		参数:long nCurrentValue——目前显示的数字,最大不能超过百分比显示精度
		说明:内部处理应该显示的百分比
		返回:S_OK——运行正常
		      S_FALSE——运行错误
	2) 显示进度2
		HRESULT ShowPercent(short nPercent);
		参数:short nPercent——欲显示的百分比,范围:0-100,否则非法,以0处理
		说明:直接显示,相当于系统提供两种百分比的显示方式
		返回:S_OK——运行正常
		      S_FALSE——运行错误
	3) 获取错误信息
		HRESULT GetErrorMessage(long nErrCode , [out]BSTR* pbstrErrMsg);
		参数:long nErrCode——错误代码
			  BSTR* pbstrErrMsg——错误信息描述
		返回:S_OK——运行正常
		      S_FALSE——运行错误
3、Events
	1) 运行错误
		HRESULT RunError(long nErrCode);
		参数:long nErrCode——运行错误值
		

功能介绍 :使用彩色渐变的效果显示进度条。

界面图片 :

部分关键代码: 

void CProcessCtrl::DrawGradient(HDC pDC,const RECT& rectClient,const int & nMaxWidth) {
	RECT		rectFill;		//显示区域
	float		fStep;			//每一步的幅宽
	HBRUSH		hBrush;			//显示的颜色画刷	

	int		nRed = 0, nGreen=0, nBlue = 0;
	float	fRefStep = 0.0, fGreenStep=0.0, fBlueStep=0.0;

	//得到不同颜色并相减,返回颜色之间的最大差值
	nRed = (GetRValue(m_nShadowEndColor)-GetRValue(m_nShadowBeginColor));
	nGreen = (GetGValue(m_nShadowEndColor)-GetGValue(m_nShadowBeginColor));
	nBlue = (GetBValue(m_nShadowEndColor)-GetBValue(m_nShadowBeginColor));
	
	//使进程条显示的总数 等于最大的颜色差值
	int		nSteps=max(abs(nRed),max(abs(nGreen),abs(nBlue)));
	
	//确定每一颜色填充多大的矩形区域
	//以下两种计算步长方式均成立,视个人喜好而定
	//fStep = (float)rectClient.right / (float)nSteps;
	fStep = (float)nMaxWidth / (float)nSteps;
	//设置每一颜色填充的步数
	fRefStep = nRed / (float)nSteps;
	fGreenStep = nGreen / (float)nSteps;
	fBlueStep = nBlue / (float)nSteps;

	nRed = GetRValue(m_nShadowBeginColor);
	nGreen = GetGValue(m_nShadowBeginColor);
	nBlue = GetBValue(m_nShadowBeginColor);
	//绘制颜色渐变的进程条
	for(int nOnBand=0 ; nOnBand < nSteps ; nOnBand++)
	{
		//本质为使用一个一个的小RECT填充客户区,而每次填充使用不同的颜色(BRUSH),从而达到渐变的效果
		::SetRect(&rectFill,
					//填充矩形区域的左上角x,y和右下角x,y
					(int)(nOnBand*fStep),
					0,
					(int)((nOnBand+1)*fStep),
					rectClient.bottom+1);
		
		hBrush = CreateSolidBrush(RGB(nRed + fRefStep*nOnBand,
								 	  nGreen + fGreenStep*nOnBand,
									  nBlue + fBlueStep*nOnBand));
		HBRUSH oldBrush = (HBRUSH)::SelectObject(pDC, hBrush);
		FillRect(pDC , &rectFill, hBrush);
		::SelectObject(pDC, oldBrush);
		DeleteObject(hBrush);
	}
}


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP