📄 prsprogresswnd.cpp
字号:
// Work out how big (and where) the progress control should be
if(0 != (m_byShowFlag & 0x01))
{
ProgressRect.SetRect(PRS_WAIT_MARGIN,
m_sizeWindow.cy - PRS_WAIT_MARGIN - m_sizeCancel.cy,
nProgressRight,
m_sizeWindow.cy - PRS_WAIT_MARGIN);
m_wndProgress.MoveWindow(ProgressRect);
m_wndProgress.ShowWindow(SW_SHOW);
}
if(0 != (m_byShowFlag & 0x08))
{
PicRect.SetRect(PRS_WAIT_MARGIN,
PRS_WAIT_MARGIN,
m_sizeWindow.cx + m_sizePic.cx - PRS_WAIT_MARGIN,
m_sizePic.cy + PRS_WAIT_MARGIN);
m_CPictureEx.MoveWindow(PicRect);
m_CPictureEx.SetBkColor(this->GetDC()->GetBkColor());
m_CPictureEx.Draw();
m_CPictureEx.ShowWindow(SW_SHOW);
}
if(0 != (m_byShowFlag & 0x04))
{
// Now reposition the controls...
m_lblPrompt.MoveWindow(m_RectPrompt);
m_lblPrompt.ShowWindow(SW_SHOW);
}
}
void CPrsProgressWnd::Clear()
{
SetText(PRS_STR_EMPTY);
SetPos(0);
m_bCancelled = FALSE;
m_nPrevPos = 0;
if (::IsWindow(GetSafeHwnd()))
{
UpdateWindow();
}
}
void CPrsProgressWnd::Hide()
{
if (!::IsWindow(GetSafeHwnd()))
{
return;
}
if (IsWindowVisible())
{
ShowWindow(SW_HIDE);
ModifyStyle(WS_VISIBLE, 0);
}
}
void CPrsProgressWnd::Show()
{
if (!::IsWindow(GetSafeHwnd()))
{
return;
}
if (!IsWindowVisible())
{
ModifyStyle(0, WS_VISIBLE);
ShowWindow(SW_SHOWNA);
RedrawWindow(NULL,NULL,RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_UPDATENOW);
}
}
void CPrsProgressWnd::SetRange(int I_nLower, int I_nUpper, int I_nStep /* = 1 */)
{
if (!::IsWindow(GetSafeHwnd()))
{
return;
}
// To take advantage of the Extended Range Values we use the PBM_SETRANGE32
// message intead of calling CProgressCtrl::SetRange directly. If this is
// being compiled under something less than VC 5.0, the necessary defines
// may not be available.
#ifdef PBM_SETRANGE32
ASSERT(-0x7FFFFFFF <= I_nLower && I_nLower <= 0x7FFFFFFF);
ASSERT(-0x7FFFFFFF <= I_nUpper && I_nUpper <= 0x7FFFFFFF);
m_wndProgress.SendMessage(PBM_SETRANGE32, (WPARAM) I_nLower, (LPARAM) I_nUpper);
#else
ASSERT(0 <= I_nLower && I_nLower <= 65535);
ASSERT(0 <= I_nUpper && I_nUpper <= 65535);
m_wndProgress.SetRange(I_nLower, I_nUpper);
#endif
m_nMaxValue = I_nUpper;
m_nMinValue = I_nLower;
m_nStep = I_nStep;
}
int CPrsProgressWnd::OffsetPos(int I_nPos)
{
if (!::IsWindow(GetSafeHwnd()))
{
return m_nPrevPos;
}
Show();
return SetPos(m_nPrevPos + I_nPos);
}
int CPrsProgressWnd::StepIt()
{
if (!::IsWindow(GetSafeHwnd()))
{
return m_nPrevPos;
}
Show();
return SetPos(m_nPrevPos + m_nStep);
}
int CPrsProgressWnd::SetStep(int I_nStep)
{
int nOldStep = m_nStep;
m_nStep = I_nStep;
if (FALSE == ::IsWindow(GetSafeHwnd()))
{
return nOldStep;
}
return m_wndProgress.SetStep(I_nStep);
}
int CPrsProgressWnd::SetPos(int I_nPos)
{
#ifdef PBM_SETRANGE32
ASSERT(-0x7FFFFFFF <= I_nPos && I_nPos <= 0x7FFFFFFF);
#else
ASSERT(0 <= I_nPos && I_nPos <= 65535);
#endif
if (FALSE == ::IsWindow(GetSafeHwnd()))
{
return m_nPrevPos;
}
if(I_nPos >= m_nMaxValue)
{
Hide();
if (TRUE == m_bModal)
{
PostMessage(WM_CLOSE);
}
CWnd *pWnd = AfxGetMainWnd();
if((NULL != pWnd) && (TRUE == ::IsWindow(pWnd->m_hWnd)))
{
pWnd->SetForegroundWindow();
}
return (m_nMaxValue);
}
Show();
CString strTitle;
int nPercentage;
m_nPrevPos = I_nPos;
if (m_nMaxValue > m_nMinValue)
{
nPercentage = (int) (((I_nPos - m_nMinValue)*100.0)/(m_nMaxValue - m_nMinValue) + 0.5);
}
else
{
nPercentage = 0;
}
// m_wndProgress.SetPos( nPercentage * 100, true, 0, 100);
if (nPercentage != m_nPrevPercent)
{
m_nPrevPercent = nPercentage;
strTitle = m_strTitle;
if(TRUE == m_bProgressBarShow)
{
strTitle.Format(_T("%s [%d%%]"), m_strTitle, nPercentage);
}
SetWindowText(strTitle);
}
return m_wndProgress.SetPos(I_nPos);
}
void CPrsProgressWnd::SetText(LPCTSTR fmt, ...)
{
m_strPrompt = PRS_STR_EMPTY;
if (FALSE == ::IsWindow(GetSafeHwnd()))
{
return;
}
va_list args;
TCHAR buffer[512];
va_start(args, fmt);
_vstprintf(buffer, fmt, args);
va_end(args);
m_lblPrompt.SetWindowText(buffer);
m_lblPrompt.GetWindowText(m_strPrompt);
}
void CPrsProgressWnd::SetCancelLabel(CString I_strCancelLabel /*= PRS_STR_EMPTY*/)
{
m_strCancelLabel = I_strCancelLabel;
}
//set the GIF File name and check it is valid or not.
BOOL CPrsProgressWnd::SetGIFInfo(CString I_strGIF, BOOL I_bProgressBarShow /*= TRUE*/)
{
m_strGIFFileName = PRS_STR_EMPTY;
m_bProgressBarShow = TRUE;
if(TRUE == m_CPictureEx.IsPlaying())
{
m_CPictureEx.Stop();
m_CPictureEx.UnLoad();
}
BOOL bRet = m_CPictureEx.Load(I_strGIF);
if(TRUE == bRet)
{
m_strGIFFileName = I_strGIF;
m_bProgressBarShow = I_bProgressBarShow;
}
return (bRet);
}
BEGIN_MESSAGE_MAP(CPrsProgressWnd, CWnd)
//{{AFX_MSG_MAP(CPrsProgressWnd)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_CANCEL, OnCancel)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrsProgressWnd message handlers
BOOL CPrsProgressWnd::OnEraseBkgnd(CDC* pDC)
{
// Fill background with Catchment background colour
CBrush backBrush(GetSysColor(COLOR_BTNFACE));
CBrush* pOldBrush = pDC->SelectObject(&backBrush);
CRect rect;
pDC->GetClipBox(&rect); // Erase the area needed
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(pOldBrush);
return TRUE;
}
void CPrsProgressWnd::OnCancel()
{
if (TRUE == m_bPersistantPosition)
{
SaveCurrentSettings();
}
m_bCancelled = TRUE;
Hide();
if (TRUE == m_bModal)
{
PostMessage(WM_CLOSE);
}
CWnd *pWnd = AfxGetMainWnd();
if((NULL != pWnd) && (TRUE == ::IsWindow(pWnd->m_hWnd)))
{
pWnd->SetForegroundWindow();
}
}
BOOL CPrsProgressWnd::DestroyWindow()
{
if (m_bPersistantPosition)
{
SaveCurrentSettings();
}
if(TRUE == m_bModal)
{
m_bModal = FALSE;
CWnd *pMainWnd = AfxGetMainWnd();
if (NULL != m_wRenenableWnd)
{
m_wRenenableWnd->EnableWindow(TRUE);
}
}
return CWnd::DestroyWindow();
}
// Message pumping function that can either be used to pump messages during
// long operations. This version will only pass messages to this window (and
// all child windows). (Thanks to Michael <mbh-ep@post5.tele.dk> for this)
void CPrsProgressWnd::PeekAndPump(BOOL I_bCancelOnESCkey /*= TRUE*/)
{
if(TRUE == m_bModal && ::GetFocus() != m_hWnd)
{
SetFocus();
}
MSG msg;
while (FALSE == m_bCancelled && ::PeekMessage(&msg, NULL,0,0,PM_NOREMOVE))
{
if (I_bCancelOnESCkey && (msg.message == WM_CHAR) && (msg.wParam == VK_ESCAPE))
{
OnCancel();
}
// Cancel button disabled if modal, so we fake it.
if (m_bModal && (msg.message == WM_LBUTTONUP))
{
CRect rect;
m_CancelButton.GetWindowRect(rect);
if (rect.PtInRect(msg.pt))
{
OnCancel();
}
}
if (!AfxGetApp()->PumpMessage())
{
::PostQuitMessage(0);
return;
}
}
}
// Retores the previous window size from the registry
void CPrsProgressWnd::GetPreviousSettings()
{
int x = AfxGetApp()->GetProfileInt(szSection, szEntryX, -1);
int y = AfxGetApp()->GetProfileInt(szSection, szEntryY, -1);
if (x >= 0 && x < GetSystemMetrics(SM_CXSCREEN) &&
y >= 0 && y < GetSystemMetrics(SM_CYSCREEN))
{
SetWindowPos(NULL, x,y, 0,0, SWP_NOSIZE|SWP_NOZORDER);
}
else
{
CenterWindow();
}
}
// Saves the current window position registry
void CPrsProgressWnd::SaveCurrentSettings()
{
if (FALSE == IsWindow(m_hWnd))
{
return;
}
CRect rect;
GetWindowRect(rect);
AfxGetApp()->WriteProfileInt(szSection, szEntryX, rect.left);
AfxGetApp()->WriteProfileInt(szSection, szEntryY, rect.top);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -