📄 bcgpstatusbar.cpp
字号:
return bOK;
}
//*******************************************************************************
void CBCGPStatusBar::SetPaneIcon (int nIndex, HICON hIcon, BOOL bUpdate)
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
// Disable animation (if exist):
SetPaneAnimation (nIndex, NULL, 0, FALSE);
if (hIcon == NULL)
{
if (pSBP->hImage != NULL)
{
::ImageList_Destroy (pSBP->hImage);
}
pSBP->hImage = NULL;
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
return;
}
ICONINFO iconInfo;
::GetIconInfo (hIcon, &iconInfo);
BITMAP bitmap;
::GetObject (iconInfo.hbmColor, sizeof (BITMAP), &bitmap);
::DeleteObject (iconInfo.hbmColor);
::DeleteObject (iconInfo.hbmMask);
if (pSBP->hImage == NULL)
{
pSBP->cxIcon = bitmap.bmWidth;
pSBP->cyIcon = bitmap.bmHeight;
pSBP->hImage = ::ImageList_Create (pSBP->cxIcon, pSBP->cyIcon,
ILC_MASK | ILC_COLORDDB, 1, 0);
::ImageList_AddIcon (pSBP->hImage, hIcon);
RecalcLayout ();
}
else
{
ASSERT (pSBP->cxIcon == bitmap.bmWidth);
ASSERT (pSBP->cyIcon == bitmap.bmHeight);
::ImageList_ReplaceIcon (pSBP->hImage, 0, hIcon);
}
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
}
//*******************************************************************************
void CBCGPStatusBar::SetPaneIcon (int nIndex, HBITMAP hBmp,
COLORREF clrTransparent, BOOL bUpdate)
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
// Disable animation (if exist):
SetPaneAnimation (nIndex, NULL, 0, FALSE);
if (hBmp == NULL)
{
if (pSBP->hImage != NULL)
{
::ImageList_Destroy (pSBP->hImage);
}
pSBP->hImage = NULL;
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
return;
}
BITMAP bitmap;
::GetObject (hBmp, sizeof (BITMAP), &bitmap);
if (pSBP->hImage == NULL)
{
pSBP->cxIcon = bitmap.bmWidth;
pSBP->cyIcon = bitmap.bmHeight;
pSBP->hImage = ::ImageList_Create (pSBP->cxIcon, pSBP->cyIcon,
ILC_MASK | ILC_COLORDDB, 1, 0);
RecalcLayout ();
}
else
{
ASSERT (pSBP->cxIcon == bitmap.bmWidth);
ASSERT (pSBP->cyIcon == bitmap.bmHeight);
::ImageList_Remove (pSBP->hImage, 0);
}
//---------------------------------------------------------
// Because ImageList_AddMasked changes the original bitmap,
// we need to create a copy:
//---------------------------------------------------------
HBITMAP hbmpCopy = (HBITMAP) ::CopyImage (hBmp, IMAGE_BITMAP, 0, 0, 0);
::ImageList_AddMasked (pSBP->hImage, hbmpCopy, clrTransparent);
::DeleteObject (hbmpCopy);
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
}
//*******************************************************************************
void CBCGPStatusBar::SetPaneAnimation (int nIndex, HIMAGELIST hImageList,
UINT nFrameRate, BOOL bUpdate)
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
if (pSBP->nFrameCount > 0)
{
KillTimer (pSBP->nID);
}
if (pSBP->hImage != NULL)
{
::ImageList_Destroy (pSBP->hImage);
pSBP->hImage = NULL;
}
pSBP->nCurrFrame = 0;
pSBP->nFrameCount = 0;
if (hImageList == NULL)
{
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
return;
}
pSBP->nFrameCount = ::ImageList_GetImageCount (hImageList);
if (pSBP->nFrameCount == 0)
{
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
return;
}
::ImageList_GetIconSize (hImageList, &pSBP->cxIcon, &pSBP->cyIcon);
pSBP->hImage = ::ImageList_Create (pSBP->cxIcon, pSBP->cyIcon,
ILC_MASK | ILC_COLORDDB, 1, 1);
for (int i =0; i < pSBP->nFrameCount; i++)
{
::ImageList_AddIcon (pSBP->hImage, ::ImageList_GetIcon (hImageList, i,
ILD_TRANSPARENT));
}
RecalcLayout ();
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
SetTimer (pSBP->nID, nFrameRate, NULL);
}
//*******************************************************************************
void CBCGPStatusBar::EnablePaneProgressBar (int nIndex, long nTotal,
BOOL bDisplayText,
COLORREF clrBar, COLORREF clrBarDest,
COLORREF clrProgressText)
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
pSBP->bProgressText = bDisplayText;
pSBP->clrProgressBar = clrBar;
pSBP->clrProgressBarDest = clrBarDest;
pSBP->nProgressTotal = nTotal;
pSBP->nProgressCurr = 0;
pSBP->clrProgressText = clrProgressText;
if (clrBarDest != (COLORREF)-1 && pSBP->bProgressText)
{
// Progress text is not available when the gradient is ON
ASSERT (FALSE);
pSBP->bProgressText = FALSE;
}
InvalidatePaneContent (nIndex);
}
//*******************************************************************************
void CBCGPStatusBar::SetPaneProgress (int nIndex, long nCurr, BOOL bUpdate)
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
ASSERT (nCurr >= 0);
ASSERT (nCurr <= pSBP->nProgressTotal);
long lPos = min (max (0, nCurr), pSBP->nProgressTotal);
if (pSBP->nProgressCurr != lPos)
{
pSBP->nProgressCurr = lPos;
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
}
}
//*******************************************************************************
void CBCGPStatusBar::SetPaneTextColor (int nIndex, COLORREF clrText, BOOL bUpdate)
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
if (pSBP->clrText != clrText)
{
pSBP->clrText = clrText;
if (bUpdate)
{
InvalidatePaneContent (nIndex);
}
}
}
//*******************************************************************************
CString CBCGPStatusBar::GetTipText(int nIndex) const
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return _T("");
}
CString s = pSBP->lpszToolTip == NULL ? _T("") : pSBP->lpszToolTip;
return s;
}
//*******************************************************************************
void CBCGPStatusBar::SetTipText(int nIndex, LPCTSTR pszTipText)
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
if (pSBP->lpszToolTip != NULL)
{
if (pszTipText != NULL && lstrcmp(pSBP->lpszToolTip, pszTipText) == 0)
{
return; // nothing to change
}
free((LPVOID)pSBP->lpszToolTip);
}
else if (pszTipText == NULL || *pszTipText == '\0')
{
return; // nothing to change
}
if (pszTipText == NULL || *pszTipText == '\0')
{
pSBP->lpszToolTip = NULL;
}
else
{
pSBP->lpszToolTip = _tcsdup(pszTipText);
}
SetBarStyle (GetBarStyle() | CBRS_TOOLTIPS);
}
//*******************************************************************************
void CBCGPStatusBar::InvalidatePaneContent (int nIndex)
{
// invalidate the text of the pane - not including the border
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
CRect rect = pSBP->rect;
if (!(pSBP->nStyle & SBPS_NOBORDERS))
rect.InflateRect(-CX_BORDER, -CY_BORDER);
else
rect.top -= CY_BORDER; // base line adjustment
InvalidateRect(rect, FALSE);
UpdateWindow ();
}
//*********************************************************************************
void CBCGPStatusBar::EnablePaneDoubleClick (BOOL bEnable)
{
m_bPaneDoubleClick = bEnable;
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPStatusBar implementation
CSize CBCGPStatusBar::CalcFixedLayout(BOOL, BOOL bHorz)
{
ASSERT_VALID(this);
// recalculate based on font height + icon height + borders
TEXTMETRIC tm;
{
CClientDC dcScreen(NULL);
HFONT hFont = GetCurrentFont ();
HGDIOBJ hOldFont = dcScreen.SelectObject(hFont);
VERIFY(dcScreen.GetTextMetrics(&tm));
dcScreen.SelectObject(hOldFont);
}
int cyIconMax = 0;
CBCGStatusBarPaneInfo* pSBP = (CBCGStatusBarPaneInfo*)m_pData;
for (int i = 0; i < m_nCount; i++, pSBP++)
{
cyIconMax = max (cyIconMax, pSBP->cyIcon);
}
CRect rectSize;
rectSize.SetRectEmpty();
CalcInsideRect(rectSize, bHorz); // will be negative size
// sizeof text + 1 or 2 extra on top, 2 on bottom + borders
return CSize(32767, max (cyIconMax, tm.tmHeight) +
CY_BORDER * 4 - rectSize.Height());
}
//*******************************************************************************
void CBCGPStatusBar::DoPaint(CDC* pDCPaint)
{
ASSERT_VALID(this);
ASSERT_VALID(pDCPaint);
CRect rectClip;
pDCPaint->GetClipBox (rectClip);
CRect rect;
GetClientRect(rect);
CDC* pDC = pDCPaint;
BOOL m_bMemDC = FALSE;
CDC dcMem;
CBitmap bmp;
CBitmap* pOldBmp = NULL;
if (dcMem.CreateCompatibleDC (pDCPaint) &&
bmp.CreateCompatibleBitmap (pDCPaint, rect.Width (), rect.Height ()))
{
//-------------------------------------------------------------
// Off-screen DC successfully created. Better paint to it then!
//-------------------------------------------------------------
m_bMemDC = TRUE;
pOldBmp = dcMem.SelectObject (&bmp);
pDC = &dcMem;
}
CBCGPControlBar::DoPaint(pDC); // draw border
HFONT hFont = GetCurrentFont ();
HGDIOBJ hOldFont = pDC->SelectObject(hFont);
int nOldMode = pDC->SetBkMode(TRANSPARENT);
COLORREF crTextColor = pDC->SetTextColor(globalData.clrBtnText);
COLORREF crBkColor = pDC->SetBkColor(globalData.clrBtnFace);
CBCGStatusBarPaneInfo* pSBP = (CBCGStatusBarPaneInfo*)m_pData;
for (int i = 0; i < m_nCount; i++, pSBP++)
{
OnDrawPane (pDC, pSBP);
}
pDC->SelectObject(hOldFont);
// draw the size box in the bottom right corner
if (!m_rectSizeBox.IsRectEmpty ())
{
CBCGPVisualManager::GetInstance ()->OnDrawStatusBarSizeBox (pDC, this,
m_rectSizeBox);
}
pDC->SetTextColor (crTextColor);
pDC->SetBkColor (crBkColor);
pDC->SetBkMode (nOldMode);
if (m_bMemDC)
{
//--------------------------------------
// Copy the results to the on-screen DC:
//--------------------------------------
pDCPaint->BitBlt (rectClip.left, rectClip.top, rectClip.Width(), rectClip.Height(),
&dcMem, rectClip.left, rectClip.top, SRCCOPY);
dcMem.SelectObject(pOldBmp);
}
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPStatusBar message handlers
BEGIN_MESSAGE_MAP(CBCGPStatusBar, CBCGPControlBar)
//{{AFX_MSG_MAP(CBCGPStatusBar)
ON_WM_NCHITTEST()
ON_WM_SYSCOMMAND()
ON_WM_SIZE()
ON_MESSAGE(WM_SETFONT, OnSetFont)
ON_MESSAGE(WM_GETFONT, OnGetFont)
ON_MESSAGE(WM_SETTEXT, OnSetText)
ON_MESSAGE(WM_GETTEXT, OnGetText)
ON_MESSAGE(WM_GETTEXTLENGTH, OnGetTextLength)
ON_WM_SETTINGCHANGE()
ON_WM_LBUTTONDBLCLK()
ON_WM_TIMER()
ON_WM_DESTROY()
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_STYLECHANGED, OnStyleChanged)
END_MESSAGE_MAP()
int CBCGPStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBCGPControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
//****************************************************************************************
void CBCGPStatusBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
if (m_bPaneDoubleClick)
{
CBCGStatusBarPaneInfo* pSBP = HitTest (point);
if (pSBP != NULL)
{
GetOwner()->PostMessage (WM_COMMAND, pSBP->nID);
}
}
CBCGPControlBar::OnLButtonDblClk(nFlags, point);
}
//**********************************************************************************
void CBCGPStatusBar::OnTimer(UINT nIDEvent)
{
CBCGPControlBar::OnTimer(nIDEvent);
int nIndex = CommandToIndex (nIDEvent);
if (nIndex < 0)
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -