📄 kcbusyprogressctrl.cpp
字号:
{
case BPC_BUSY_PINGPONG:
{
// do a check for the left to right movement
if ( m_nCurPos >= nNumSteps-1 )
m_nStep = -1;
// check if we're done moving from right to left..
if ( m_nCurPos <= 0 )
m_nStep = 1;
}
break;
case BPC_BUSY_LTR:
{
if ( m_nCurPos == nNumSteps-1 )
m_nCurPos = -1;
}
break;
case BPC_BUSY_RTL:
{
if ( m_nCurPos == 0 )
m_nCurPos = nNumSteps;
}
break;
}
}
else if ( m_nMode & BPC_MODE_PROGRESS )
{
}
// update the position
m_nCurPos += m_nStep;
Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
void CKCBusyProgressCtrl::SetMode(int nMode)
{
End();
if ( m_nMode >= BPC_MODE_BUSY && m_nMode <= BPC_MODE_PROGRESS )
{
m_nMode = nMode;
if ( m_nMode == BPC_MODE_PROGRESS )
m_nStep = 1;
}
}
/////////////////////////////////////////////////////////////////////////////
void CKCBusyProgressCtrl::Start()
{
if ( m_nMode & BPC_MODE_BUSY)
{
while ( m_pThrd || m_bBusyThrd)
End();
m_pThrd = AfxBeginThread(thrdBusy, this);
m_pThrd->m_bAutoDelete = false;
}
}
/////////////////////////////////////////////////////////////////////////////
void CKCBusyProgressCtrl::End()
{
if ( m_pThrd )
{
if ( m_bBusyThrd )
m_bBusyThrd = false;
WaitForSingleObject(m_pThrd->m_hThread, m_nSpeed*2);
delete m_pThrd;
m_pThrd = NULL;
}
else
m_bBusyThrd = false;
}
/////////////////////////////////////////////////////////////////////////////
UINT CKCBusyProgressCtrl::thrdBusy(LPVOID pParam)
{
CKCBusyProgressCtrl* pThis = (CKCBusyProgressCtrl*) pParam;
if ( !pThis )
return -1;
while ( pThis->m_bBusyThrd )
Sleep(pThis->m_nSpeed);
pThis->m_bBusyThrd = true;
while ( pThis->m_bBusyThrd )
{
pThis->StepIt();
Sleep(pThis->m_nSpeed);
}
pThis->m_bBusyThrd = false;
return 0;
}
/////////////////////////////////////////////////////////////////////////////
void CKCBusyProgressCtrl::Reset()
{
if ( m_nMode == BPC_MODE_BUSY )
{
m_nCurPos = m_nBusyType != BPC_BUSY_RTL ? 0 :
m_nBusyFill != BPC_BUSYFILL_SMOOTH ? m_nNumSteps :
m_nNumSteps * m_nGranularity;
m_nStep = m_nBusyType != BPC_BUSY_RTL ? 1 : -1;
}
else
{
m_nCurPos = 0;
m_nStep = 1;
}
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetNumSteps(WPARAM wParam, LPARAM lParam)
{
SetNumSteps((int)wParam);
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetCurPos(WPARAM wParam, LPARAM lParam)
{
SetCurPos( (int)wParam );
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetIBPad(WPARAM wParam, LPARAM lParam)
{
SetInterBlockPadding( (int) wParam );
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetSpeed(WPARAM wParam, LPARAM lParam)
{
SetSpeed( (int) wParam );
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetRange(WPARAM wParam, LPARAM lParam)
{
SetRange( (int) wParam, (int) lParam );
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetMode(WPARAM wParam, LPARAM lParam)
{
SetMode( (int) wParam );
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnStartBusy(WPARAM wParam, LPARAM lParam)
{
Start();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnEndBusy(WPARAM wParam, LPARAM lParam)
{
End();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnStepIt(WPARAM wParam, LPARAM lParam)
{
StepIt();
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetBusyType(WPARAM wParam, LPARAM lParam)
{
SetBusyType( (int) wParam );
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetBusyFill(WPARAM wParam, LPARAM lParam)
{
SetBusyFill( (int) wParam );
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetGranularity(WPARAM wParam, LPARAM lParam)
{
SetGranularity((int) wParam);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetColBkg(WPARAM wParam, LPARAM lParam)
{
SetColBkg( (COLORREF) wParam );
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetColBFace(WPARAM wParam, LPARAM lParam)
{
SetColBlockFace( (COLORREF) wParam );
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetColBEdge(WPARAM wParam, LPARAM lParam)
{
SetColBlockEdge( (COLORREF) wParam );
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetColBFaceHi(WPARAM wParam, LPARAM lParam)
{
SetColBlockFaceHi( (COLORREF) wParam );
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnSetColBEdgeHi(WPARAM wParam, LPARAM lParam)
{
SetColBlockEdgeHi( (COLORREF) wParam );
Invalidate();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnRecalc(WPARAM wParam, LPARAM lParam)
{
Recalc();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnReset(WPARAM wParam, LPARAM lParam)
{
Reset();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
LRESULT CKCBusyProgressCtrl::OnUseSysCol(WPARAM wParam, LPARAM lParam)
{
UseSysColBkg( wParam ? true : false );
return 0;
}
/////////////////////////////////////////////////////////////////////////////
void CKCBusyProgressCtrl::UseSysColBkg(bool bUse)
{
m_bUseSysColBkg = bUse;
if ( bUse )
m_colBkg = GetSysColor(COLOR_3DFACE);
Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
void CKCBusyProgressCtrl::OnSysColorChange()
{
CStatic::OnSysColorChange();
if ( m_bUseSysColBkg )
{
m_colBkg = GetSysColor(COLOR_3DFACE);
Invalidate();
}
}
/////////////////////////////////////////////////////////////////////////////
void CKCBusyProgressCtrl::SetBusyType(int nType)
{
m_nBusyType = nType;
if ( m_nMode == BPC_MODE_BUSY )
{
switch ( nType )
{
case BPC_BUSY_LTR:
m_nStep = 1;
break;
case BPC_BUSY_RTL:
m_nStep = -1;
break;
case BPC_BUSY_PINGPONG:
default:
break;
}
}
}
/////////////////////////////////////////////////////////////////////////////
void CKCBusyProgressCtrl::SetBusyFill(int nFill)
{
if ( m_nMode == BPC_MODE_BUSY )
{
m_nBusyFill = nFill;
switch ( nFill )
{
case BPC_BUSYFILL_SMOOTH:
Reset();
m_nNumStepsSmooth = m_nNumSteps * m_nGranularity;
break;
case BPC_BUSYFILL_BLOCK:
default:
Reset();
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -