progressbartestdlg.cpp
来自「这是一个可以增强进度条功能的一个类」· C++ 代码 · 共 743 行 · 第 1/2 页
CPP
743 行
m_progressH.SetGradientColors(gray, dkgray);
m_progressV.SetGradientColors(gray, dkgray);
m_progressH.SetTextColor(black, black);
m_progressV.SetTextColor(black, black);
m_fUseBrush = FALSE;
m_nBorder = 0;
m_iTextMode = 0;
m_iProgressMode = SNAKE;
UpdateData(FALSE);
OnCheckBrush();
OnChangeEditBorder();
OnRadioTextMode();
OnRadioProgressMode();
}
void CProgressBarTestDlg::OnCheckBrush()
{
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
CBrush* pbrBar = NULL, *pbrBk = NULL;
if(m_fUseBrush)
{
pbrBar = &m_brBar;
pbrBk = &m_brBk;
}
m_progressH.SetBarBrush(pbrBar);
m_progressH.SetBkBrush(pbrBk);
m_progressV.SetBarBrush(pbrBar);
m_progressV.SetBkBrush(pbrBk);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnCheckRubberbar()
{
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
m_progressH.SetRubberBar(m_fRubberBar);
m_progressV.SetRubberBar(m_fRubberBar);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnCheckTiedtext()
{
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
m_progressH.SetTiedText(m_fTiedText);
m_progressV.SetTiedText(m_fTiedText);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnCheckVerttext()
{
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
m_progressV.SetFont(m_fVertText ? &m_fontV : &m_fontH);
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnClrBk()
{
// TODO: Add your control notification handler code here
COLORREF clrBk = m_progressH.GetBkColor();
CColorDialog dlg(clrBk, CC_SOLIDCOLOR, this);
if(dlg.DoModal() != IDOK)
return;
clrBk = dlg.GetColor();
m_progressH.SetBkColor(clrBk);
m_progressV.SetBkColor(clrBk);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnClrEnd()
{
// TODO: Add your control notification handler code here
COLORREF clrStart, clrEnd;
m_progressH.GetGradientColors(clrStart, clrEnd);
CColorDialog dlg(clrEnd, CC_ANYCOLOR, this);
if(dlg.DoModal() != IDOK)
return;
clrEnd = dlg.GetColor();
m_progressH.SetGradientColors(clrStart, clrEnd);
m_progressV.SetGradientColors(clrStart, clrEnd);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnClrStart()
{
// TODO: Add your control notification handler code here
COLORREF clrStart, clrEnd;
m_progressH.GetGradientColors(clrStart, clrEnd);
CColorDialog dlg(clrStart, CC_ANYCOLOR, this);
if(dlg.DoModal() != IDOK)
return;
clrStart = dlg.GetColor();
m_progressH.SetGradientColors(clrStart, clrEnd);
m_progressV.SetGradientColors(clrStart, clrEnd);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnClrTextBk()
{
// TODO: Add your control notification handler code here
COLORREF clrTextOnBar = m_progressH.GetTextColor();
COLORREF clrTextOnBk = m_progressH.GetTextColorOnBk();
CColorDialog dlg(clrTextOnBk, CC_SOLIDCOLOR, this);
if(dlg.DoModal() != IDOK)
return;
clrTextOnBk = dlg.GetColor();
m_progressH.SetTextColor(clrTextOnBar, clrTextOnBk);
m_progressV.SetTextColor(clrTextOnBar, clrTextOnBk);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnClrTextBar()
{
// TODO: Add your control notification handler code here
COLORREF clrTextOnBar = m_progressH.GetTextColor();
COLORREF clrTextOnBk = m_progressH.GetTextColorOnBk();
CColorDialog dlg(clrTextOnBar, CC_SOLIDCOLOR, this);
if(dlg.DoModal() != IDOK)
return;
clrTextOnBar = dlg.GetColor();
m_progressH.SetTextColor(clrTextOnBar, clrTextOnBk);
m_progressV.SetTextColor(clrTextOnBar, clrTextOnBk);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnChangeEditBorder()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
CRect rcBorders(m_nBorder, m_nBorder, m_nBorder, m_nBorder);
m_progressH.SetBorders(rcBorders);
m_progressV.SetBorders(rcBorders);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnRadioTextMode()
{
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
switch(m_iTextMode)
{
case 0:
m_progressH.HideText();
m_progressV.HideText();
break;
case 1:
m_progressH.SetTextFormat("%d%%", PBS_SHOW_PERCENT); // also can use SetShowPercent()
m_progressV.SetTextFormat("%d%%", PBS_SHOW_PERCENT);
break;
case 2:
m_progressH.SetTextFormat("%d", PBS_SHOW_POSITION);
m_progressV.SetTextFormat("%d", PBS_SHOW_POSITION);
break;
case 3:
m_progressH.SetTextFormat("Done : %d%%", PBS_SHOW_PERCENT);
m_progressV.SetTextFormat("Done : %d%%", PBS_SHOW_PERCENT);
break;
case 4:
m_progressH.SetTextFormat("Done : %d", PBS_SHOW_POSITION);
m_progressV.SetTextFormat("Done : %d", PBS_SHOW_POSITION);
break;
case 5:
m_progressH.SetTextFormat("Text");
m_progressV.SetTextFormat("Text");
break;
}
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnRadioProgressMode()
{
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
m_progressH.SetSnake(m_iProgressMode == SNAKE);
m_progressV.SetSnake(m_iProgressMode == SNAKE);
// snake mode includes rubberbur mode
m_fRubberBar = m_progressH.GetRubberBar()?1:0;
UpdateData(FALSE);
}
void CProgressBarTestDlg::OnChangeRange()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
m_progressH.SetRange32(BASE, BASE+m_nRange);
m_progressV.SetRange32(BASE, BASE+m_nRange);
m_progressH.SetPos(BASE+m_pos);
m_progressV.SetPos(BASE+m_pos);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnReset()
{
// TODO: Add your control notification handler code here
m_pos = 0;
m_inc = TRUE;
m_progressH.SetPos(BASE+m_pos);
m_progressV.SetPos(BASE+m_pos);
}
void CProgressBarTestDlg::OnReverse()
{
// TODO: Add your control notification handler code here
if(m_progressH.GetStyle()&PBS_REVERSE)
{
m_progressH.ModifyStyle(PBS_REVERSE, 0);
m_progressV.ModifyStyle(PBS_REVERSE, 0);
}
else
{
m_progressH.ModifyStyle(0, PBS_REVERSE);
m_progressV.ModifyStyle(0, PBS_REVERSE);
}
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnStep()
{
// TODO: Add your control notification handler code here
if(m_iProgressMode == PROGRESS)
{
m_pos+=m_nStepSize;
if((UINT)m_pos > m_nRange)
m_pos = 0;
m_progressH.SetPos(BASE+m_pos);
m_progressV.SetPos(BASE+m_pos);
}
else
{
m_progressH.StepIt();
m_progressV.StepIt();
}
}
void CProgressBarTestDlg::OnChangeStepsize()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
m_progressH.SetStep(m_nStepSize);
m_progressV.SetStep(m_nStepSize);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnChangeTail()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
m_progressH.SetSnakeTail(m_nTailSize);
m_progressV.SetSnakeTail(m_nTailSize);
m_progressH.Invalidate();
m_progressV.Invalidate();
}
void CProgressBarTestDlg::OnButtonMySnake()
{
// TODO: Add your control notification handler code here
COLORREF black = RGB(0,0,0);
COLORREF gray = RGB(192,192,192);
COLORREF dkgray = RGB(128,128,128);
m_progressH.SetBkColor(gray);
m_progressV.SetBkColor(gray);
m_progressH.SetGradientColorsX(3, gray, dkgray, gray);
m_progressV.SetGradientColorsX(3, gray, dkgray, gray);
m_progressH.SetTextColor(black, gray);
m_progressV.SetTextColor(black, gray);
m_fUseBrush = FALSE;
m_nBorder = 0;
m_iTextMode = 0;
m_iProgressMode = SNAKE;
UpdateData(FALSE);
OnCheckBrush();
OnChangeEditBorder();
OnRadioTextMode();
OnRadioProgressMode();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?