statusbaract.cpp
来自「管理项目进度工具的原代码」· C++ 代码 · 共 526 行 · 第 1/2 页
CPP
526 行
if (lpszText == NULL || *lpszText == _T('\0'))
m_tooltip.DelTool(this, nIndex + 1);
else if (! m_tooltip.GetToolInfo(ti, this, nIndex + 1))
{
// get bounding rect of pane, and add tool
// add one to index, as tooltips don't allow ids of 0
CRect rc;
GetItemRect(nIndex, &rc);
m_tooltip.AddTool(this, lpszText, rc, nIndex + 1);
}
else
m_tooltip.UpdateTipText(lpszText, this, nIndex + 1);
return TRUE;
}
// sets a pane's tool-tip text to a resource ID, by the pane's ID
BOOL CStatusBarACT::SetPaneTooltip(UINT nID, UINT nTipID)
{
return SetPaneTooltipIndex(CommandToIndex(nID), nTipID);
}
// sets a pane's tool-tip text to a resource ID, by the pane's index
BOOL CStatusBarACT::SetPaneTooltipIndex(int nIndex, UINT nTipID)
{
CString sTip;
if (! sTip.LoadString(nTipID))
return FALSE;
return SetPaneTooltipIndex(nIndex, sTip);
}
// need to tell the tooltips when the 'tools' have moved
// for each pane, get new rect, and pass to the tooltip control
void CStatusBarACT::UpdateTooltipRects()
{
int nMax = GetStatusBarCtrl().GetParts(0, NULL);
for (int n = 0; n < nMax; n++)
{
CRect rc;
GetItemRect(n, &rc);
m_tooltip.SetToolRect(this, n + 1, &rc);
}
}
// need to tell the tooltips that the 'tools' have moved
void CStatusBarACT::OnSize(UINT nType, int cx, int cy)
{
CStatusBar::OnSize(nType, cx, cy);
if (::IsWindow(m_hWnd))
UpdateTooltipRects();
}
// re-size the specified pane to exactly fit its text
void CStatusBarACT::AutoFitPane(int nIndex)
{
if (nIndex < 0 || nIndex >= GetStatusBarCtrl().GetParts(0, NULL))
return;
// get dc, and get text width on bar, then re-size pane to fit
try{
CClientDC dc(this);
CRect rc(0, 0, 0, 0);
CFont* pFont = GetFont(); // get the status bar font, so it gets the size correct
CFont* pFontOld = NULL;
if (pFont == NULL)
pFontOld = (CFont*)dc.SelectStockObject(ANSI_VAR_FONT);
else
pFontOld = dc.SelectObject(pFont);
CString sText = GetPaneText(nIndex);
int nPos = sText.Find(_T('\n'));
if (nPos != -1)
sText = sText.Left(nPos);
dc.DrawText(sText, &rc, DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX);
dc.SelectObject(pFontOld);
int nWidth;
UINT nID, nStyle;
GetPaneInfo(nIndex, nID, nStyle, nWidth);
nWidth = rc.Width();
SetPaneInfo(nIndex, nID, nStyle, nWidth);
// need to tell the tooltips that the 'tools' have moved
UpdateTooltipRects();
}catch(...){ ; }
}
LRESULT CStatusBarACT::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case SB_SETTEXT:
{
CString sText = (LPCTSTR)lParam;
CString sTip;
BOOL bHasTip = FALSE;
int nPos = sText.Find(_T('\n'));
if (nPos != -1)
{
bHasTip = TRUE;
sTip = sText.Mid(nPos+1);
sText = sText.Left(nPos);
lParam = (LPARAM)(LPCTSTR)sText;
}
LRESULT lResult = CStatusBar::DefWindowProc(message, wParam, lParam);
int nIndex = wParam & 0xff;
if (m_adwFlags.GetSize() > nIndex && m_adwFlags[nIndex] & SBACTF_AUTOFIT)
AutoFitPane(nIndex);
if (bHasTip)
SetPaneTooltipIndex(nIndex, sTip);
return lResult;
}
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_LBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
{
CPoint pt(lParam);
SendPaneCommand(pt, message);
}
break;
};
return CStatusBar::DefWindowProc(message, wParam, lParam);
}
// called to add panes to the status bar
BOOL CStatusBarACT::SetPanes(LPSBACTPANEINFO lpsbactpi, UINT nPaneInfoCount)
{
if (lpsbactpi == NULL || nPaneInfoCount <= 0)
return FALSE;
// first set the standard info (IDs)
UINT* anIDs = new UINT[nPaneInfoCount];
UINT n;
for (n = 0; n < nPaneInfoCount; n++)
anIDs[n] = lpsbactpi[n].nID;
BOOL bResult = SetIndicators(anIDs, nPaneInfoCount);
delete [] anIDs;
// now set our info
for (n = 0; n < nPaneInfoCount; n++)
{
if (lpsbactpi[n].dwFlags & SBACTF_RESOURCETIP)
SetPaneTooltip(lpsbactpi[n].nID, (UINT)lpsbactpi[n].lpszTip);
else
SetPaneTooltip(lpsbactpi[n].nID, lpsbactpi[n].lpszTip);
SetPaneFlags(lpsbactpi[n].nID, lpsbactpi[n].dwFlags);
SetPaneCursor(lpsbactpi[n].nID, lpsbactpi[n].lpszCursor);
}
return bResult;
}
// called to modify a pane
BOOL CStatusBarACT::SetPane(LPSBACTPANEINFO lpsbactpi)
{
if (lpsbactpi == NULL)
return FALSE;
int nIndex = CommandToIndex(lpsbactpi->nID);
int nMax = GetStatusBarCtrl().GetParts(0, NULL);
if (nIndex < nMax)
return FALSE;
SetPaneTooltipIndex(nIndex, lpsbactpi->lpszTip);
SetPaneFlagsIndex(nIndex, lpsbactpi->dwFlags);
SetPaneCursorIndex(nIndex, lpsbactpi->lpszCursor);
return TRUE;
}
// sets the cursor for a pane by the pane's index
BOOL CStatusBarACT::SetPaneCursorIndex(int nIndex, HCURSOR hCursor)
{
// make sure array is big enough
int nMax = GetStatusBarCtrl().GetParts(0, NULL);
if (nIndex >= nMax || nIndex < 0)
return FALSE;
m_adwCursors.SetAtGrow(nIndex, hCursor);
return TRUE;
}
// sets the cursor for a pane by the pane's ID
BOOL CStatusBarACT::SetPaneCursor(UINT nID, HCURSOR hCursor)
{
return SetPaneCursorIndex(CommandToIndex(nID), hCursor);
}
// sets the cursor for a pane by the pane's index
BOOL CStatusBarACT::SetPaneCursorIndex(int nIndex, LPCTSTR lpszCursor)
{
// make sure array is big enough
int nMax = GetStatusBarCtrl().GetParts(0, NULL);
if (nIndex >= nMax || nIndex < 0)
return FALSE;
// get cursor handle and add to array of handles
HCURSOR hCursor = NULL;
if (lpszCursor != NULL)
{
CWinApp* pApp = AfxGetApp();
ASSERT(pApp != NULL);
if (pApp == NULL)
return FALSE;
hCursor = pApp->LoadCursor(lpszCursor);
}
SetPaneCursorIndex(nIndex, hCursor);
return TRUE;
}
// sets the cursor for a pane by the pane's ID
BOOL CStatusBarACT::SetPaneCursor(UINT nID, LPCTSTR lpszCursor)
{
return SetPaneCursorIndex(CommandToIndex(nID), lpszCursor);
}
// sets the cursor for a pane by the pane's index
BOOL CStatusBarACT::SetPaneCursorIndex(int nIndex, UINT nCursorID)
{
return SetPaneCursorIndex(nIndex, MAKEINTRESOURCE(nCursorID));
}
// sets the cursor for a pane by the pane's ID
BOOL CStatusBarACT::SetPaneCursor(UINT nID, UINT nCursorID)
{
return SetPaneCursorIndex(CommandToIndex(nID), MAKEINTRESOURCE(nCursorID));
}
HCURSOR CStatusBarACT::GetPaneCursorIndex(int nIndex)
{
// make sure array is big enough
int nMax = GetStatusBarCtrl().GetParts(0, NULL);
if (nIndex >= nMax || nIndex < 0 || m_adwCursors.GetSize() <= nIndex)
return 0;
return m_adwCursors[nIndex];
}
HCURSOR CStatusBarACT::GetPaneCursor(UINT nID)
{
return GetPaneCursorIndex(CommandToIndex(nID));
}
BOOL CStatusBarACT::SetHandCursor(UINT nCursorID, BOOL bTryDefault/*=TRUE*/)
{
return SetHandCursor(MAKEINTRESOURCE(nCursorID), bTryDefault);
}
BOOL CStatusBarACT::SetHandCursor(LPCTSTR lpszCursorID, BOOL bTryDefault/*=TRUE*/)
{
CWinApp* pApp = AfxGetApp();
ASSERT(pApp != NULL);
if (pApp == NULL)
return FALSE;
SetHandCursor(pApp->LoadCursor(lpszCursorID), bTryDefault);
return (m_hCursorHand != NULL);
}
void CStatusBarACT::SetHandCursor(HCURSOR hCursor, BOOL bTryDefault/*=TRUE*/)
{
m_hCursorHand = hCursor;
m_bTryDefaultHandCursor = bTryDefault;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?