📄 appbar.cpp
字号:
BOOL CAppBar::UnRegister()
{
APPBARDATA abd;
abd.cbSize = sizeof(APPBARDATA);
abd.hWnd = m_hWnd;
m_bAppRegistered = !SHAppBarMessage(ABM_REMOVE, &abd);
return !m_bAppRegistered;
}
//
// SetAutoHide -- Causes the appbar window to either auto hide or stop auto hiding.
//
BOOL CAppBar::SetAutoHide(BOOL bHide)
{
if (bHide)
{
return AutoHide ();
}
else
{
return NoAutoHide ();
}
}
//
// AutoHide -- Does the work of changing the appbar to autohide. We check
// -- to see if we can autohide, and if so unregister and tell
// -- the system we are autohiding.
//
BOOL CAppBar::AutoHide()
{
HWND hwndAutoHide;
APPBARDATA abd;
POPTIONS pOpt = GetAppbarData();
BOOL bSuccess;
RECT rc;
CString strMsg;
abd.cbSize = sizeof(APPBARDATA);
abd.hWnd = m_hWnd;
abd.uEdge = pOpt->uSide;
// First figure out if someone already has this side for
// autohiding
hwndAutoHide = (HWND) SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
if (hwndAutoHide != NULL)
{
return FALSE;
}
// We can autohide on this edge. Set the autohide style.
abd.lParam = TRUE;
bSuccess = (BOOL) SHAppBarMessage(ABM_SETAUTOHIDEBAR, &abd);
if (!bSuccess)
{
#ifdef LOG
strMsg.LoadString (IDS_ERROR_AUTOHIDE);
gLog.WriteError (strMsg);
#endif
return FALSE;
}
else
{
// Since we're allowed to autohide, we need to adjust our screen
// rectangle to the autohidden position. This will allow the system
// to resize the desktop.
pOpt->fAutoHide = TRUE;
m_dwWidth = pOpt->cxWidth;
m_dwHeight = pOpt->cyHeight;
rc = m_rcAppBar;
switch (pOpt->uSide)
{
case ABE_TOP:
rc.bottom = rc.top + 2;
break;
case ABE_BOTTOM:
rc.top = rc.bottom - 2;
break;
case ABE_LEFT:
rc.right = rc.left + 2;
break;
case ABE_RIGHT:
rc.left = rc.right - 2;
break;
}
QuerySetPos(pOpt->uSide, &rc, &abd, TRUE);
}
return TRUE;
}
BOOL CAppBar::NoAutoHide()
{
HWND hwndAutoHide;
APPBARDATA abd;
POPTIONS pOpt = GetAppbarData();
BOOL fSuccess;
CString strMsg;
abd.cbSize = sizeof(APPBARDATA);
abd.hWnd = m_hWnd;
abd.uEdge = pOpt->uSide;
// First let's check to see if we're the appbar attached to the
// side of the screen
abd.uEdge = pOpt->uSide;
hwndAutoHide = (HWND) SHAppBarMessage(ABM_GETAUTOHIDEBAR, &abd);
if (hwndAutoHide != m_hWnd)
{
strMsg.Format ("%s", STR_ERROR_NOT_HIDDEN);
TRACE (strMsg);
return FALSE;
}
// We can autohide or stop autohide on this edge. Set the autohide style.
abd.lParam = FALSE;
fSuccess = (BOOL) SHAppBarMessage(ABM_SETAUTOHIDEBAR, &abd);
if (!fSuccess)
{
strMsg.Format ("%s", STR_ERROR_SET_AUTOHIDE);
TRACE (strMsg);
return FALSE;
}
else
{
// Need to change the appbar to get the screen desktop space
// back. Also need to reattach the appbar to that edge of the
// screen.
pOpt->fAutoHide = FALSE;
pOpt->cxWidth = m_dwWidth;
pOpt->cyHeight = m_dwHeight;
SetSide (pOpt->uSide);
}
return (TRUE);
}
BOOL CAppBar::SetSide(UINT uSide)
{
APPBARDATA abd;
RECT rc;
POPTIONS pOpt = GetAppbarData();
BOOL fAutoHide = FALSE;
// Calculate the size of the screen so we can occupy the full width or
// height of the screen on the edge we request.
rc.top = 0;
rc.left = 0;
rc.right = GetSystemMetrics(SM_CXSCREEN);
rc.bottom = GetSystemMetrics(SM_CYSCREEN);
// Fill out the APPBARDATA struct with the basic information
abd.cbSize = sizeof(APPBARDATA);
abd.hWnd = m_hWnd;
// If the appbar is autohidden, turn that off so we can move the bar
if (pOpt->fAutoHide)
{
fAutoHide = pOpt->fAutoHide;
// Turn off the redrawing of the desktop while we move things around.
// If you put any breakpoints in this area you will lock up the desktop
// Since turning off the desktop repaints turns it off for all the apps
// in the system
SetWindowRedraw (GetDesktopWindow(), FALSE);
SetAutoHide (FALSE);
}
// Adjust the rectangle to set our height or width depending on the
// side we want.
switch (uSide)
{
case ABE_TOP:
rc.bottom = rc.top + pOpt->cyHeight;
break;
case ABE_BOTTOM:
rc.top = rc.bottom - pOpt->cyHeight;
break;
case ABE_LEFT:
rc.right = rc.left + pOpt->cxWidth;
break;
case ABE_RIGHT:
rc.left = rc.right - pOpt->cxWidth;
break;
}
// Move the appbar to the new screen space.
QuerySetPos(uSide, &rc, &abd, TRUE);
// If the appbar was hidden, rehide it now
if (fAutoHide)
{
SetAutoHide (TRUE);
SetWindowRedraw (GetDesktopWindow(), TRUE);
RedrawWindow (GetDesktopWindow(), NULL, NULL,
RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
}
return TRUE;
}
void CAppBar::SetAlwaysOnTop(BOOL bOnTop)
{
POPTIONS pOpt = GetAppbarData();
// Update the window position to HWND_TOPMOST if we're to be always
// on top, or HWND_NOTOPMOST if we're not.
SetWindowPos(m_hWnd, (bOnTop) ? HWND_TOPMOST : HWND_NOTOPMOST,
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
// Store the setting in the appbar OPTIONS struct.
pOpt->fOnTop = bOnTop;
}
void CAppBar::Hide()
{
POPTIONS pOpt = GetAppbarData ();
RECT rc;
// Don't want to hide if AutoHide not set
if (!pOpt->fAutoHide)
{
return;
}
// Calculate a hidden rectangle to use
rc = m_rcAppBar;
switch (pOpt->uSide)
{
case ABE_TOP:
rc.bottom = rc.top + 2;
break;
case ABE_BOTTOM:
rc.top = rc.bottom - 2;
break;
case ABE_LEFT:
rc.right = rc.left + 2;
break;
case ABE_RIGHT:
rc.left = rc.right - 2;
break;
}
pOpt->fHiding = TRUE;
CUtility Util;
Util.SlideWindow (m_hWnd, &rc);
}
void CAppBar::UnHide()
{
POPTIONS pOpt = GetAppbarData();
CUtility Util;
Util.SlideWindow (m_hWnd, &m_rcAppBar);
pOpt->fHiding = FALSE;
SetAutoHideTimer ();
}
void CAppBar::SetAutoHideTimer()
{
POPTIONS pOpt = GetAppbarData();
if (pOpt->fAutoHide)
{
SetTimer (m_hWnd, IDT_AUTOHIDE, 500, NULL);
}
}
void CAppBar::SetAutoUnhideTimer()
{
POPTIONS pOpt = GetAppbarData();
if (pOpt->fAutoHide && pOpt->fHiding)
{
SetTimer(m_hWnd, IDT_AUTOUNHIDE, 50, NULL);
}
}
POPTIONS CAppBar::GetAppbarData()
{
return m_pOptions;
}
BOOL CAppBar::SetAppbarData (POPTIONS pOptions)
{
if (!m_pOptions)
{
return FALSE;
}
m_pOptions->fAutoHide = pOptions->fAutoHide;
m_pOptions->fOnTop = pOptions->fOnTop;
m_pOptions->fHiding = pOptions->fHiding;
m_pOptions->uSide = pOptions->uSide;
m_pOptions->cxWidth = pOptions->cxWidth;
m_pOptions->cyHeight = pOptions->cyHeight;
for (int idx=0; idx<4; idx++)
{
m_pOptions->rcEdges[idx] = pOptions->rcEdges[idx];
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -