进度条管理类

//AcProgressBar.h

/************************************************************************
*说明:定义和实现一个与AutoCAD状态栏上显示进度栏的类
*
*
*
*

************************************************************************/

#pragma once

class AcProgressBar
{
public:
AcProgressBar();
~AcProgressBar();
//创建
BOOL Create(CString strHint , int nMaxPos , int nMinPos = 0);
//设置当前位置
BOOL setCutPos(CString strHint , int nPos);
BOOL setCutPos(int nPos);
//移动
BOOL stepIt(int nStep=1){return setCutPos(m_nCurPos+nStep);}
//重置
void Restore();
//获取当前位置
int getCurPos(){return m_nCurPos;}
BOOL IsCreate(){return m_bCreate;}

private:
BOOL m_bCreate;
int m_nMinPos;
int m_nMaxPos;
int m_nCurPos;
};

//AcProgressBar.cpp

#include “StdAfx.h”
#include “AcProgressBar.h”

AcProgressBar::AcProgressBar()
{
m_bCreate = FALSE;
m_nMaxPos = m_nMinPos = m_nCurPos = 0;
}

AcProgressBar::~AcProgressBar()
{
this->Restore();
}

BOOL AcProgressBar::Create(CString strHint , int nMaxPos , int nMinPos /* = 0 */)
{
if ((nMaxPos <= 0) || (nMaxPos <= nMinPos))
return FALSE;

if(acedSetStatusBarProgressMeter(strHint , 0 , 100) != 0)
return FALSE;

m_bCreate = TRUE;
m_nMaxPos = nMaxPos;
m_nMinPos = nMinPos;

return TRUE;
}

void AcProgressBar::Restore()
{
if(!m_bCreate)
return;

acedRestoreStatusBar();
m_bCreate = FALSE;
m_nMaxPos = m_nMinPos = m_nCurPos = 0;
}

BOOL AcProgressBar::setCutPos(int nPos)
{
if(!m_bCreate)
return FALSE;

if(nPos > m_nMaxPos)
nPos = m_nMaxPos;

// 换算成0~100之间的值
nPos = double(nPos)/(m_nMaxPos-m_nMinPos)*100;

if (m_nCurPos == nPos)
return TRUE;
else
m_nCurPos = nPos;

if(acedSetStatusBarProgressMeterPos(nPos) != 0)
return FALSE;

return TRUE;
}

BOOL AcProgressBar::setCutPos(CString strHint , int nPos)
{
if(!m_bCreate)
return FALSE;

if(m_bCreate)
{
m_bCreate = FALSE;
acedRestoreStatusBar();
}

if(acedSetStatusBarProgressMeter(strHint , m_nMinPos , m_nMaxPos) != 0)
return FALSE;

m_bCreate = TRUE;

if(nPos > m_nMaxPos)
nPos = m_nMaxPos;

// 换算成0~100之间的值
nPos = double(nPos)/(m_nMaxPos-m_nMinPos)*100;

if (m_nCurPos == nPos)
return TRUE;
else
m_nCurPos = nPos;

if(acedSetStatusBarProgressMeterPos(nPos) != 0)
return FALSE;

return TRUE;
}

此条目发表在ObjectArx分类目录,贴了, 标签。将固定链接加入收藏夹。

发表评论