📄 atlctrlw.h
字号:
T* pT = static_cast<T*>(this);
pT->DoPopupMenu(nIndex, false);
return 0;
}
LRESULT OnInternalGetBar(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// Let's make sure we're not embedded in another process
if((LPVOID)wParam != NULL)
*((DWORD*)wParam) = GetCurrentProcessId();
if(IsWindowVisible())
return (LRESULT)static_cast<CCommandBarCtrlBase*>(this);
else
return NULL;
}
LRESULT OnSettingChange(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
#ifndef SPI_GETKEYBOARDCUES
const UINT SPI_SETKEYBOARDCUES = 0x100B;
#endif // !SPI_GETKEYBOARDCUES
#ifndef SPI_GETFLATMENU
const UINT SPI_SETFLATMENU = 0x1023;
#endif // !SPI_GETFLATMENU
if(wParam == SPI_SETNONCLIENTMETRICS || wParam == SPI_SETKEYBOARDCUES || wParam == SPI_SETFLATMENU)
{
T* pT = static_cast<T*>(this);
pT->GetSystemSettings();
}
return 0;
}
LRESULT OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
LRESULT lRet = DefWindowProc(uMsg, wParam, lParam);
LPWINDOWPOS lpWP = (LPWINDOWPOS)lParam;
int cyMin = ::GetSystemMetrics(SM_CYMENU);
if(lpWP->cy < cyMin)
lpWP->cy = cyMin;
return lRet;
}
LRESULT OnMenuChar(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
#ifdef _CMDBAR_EXTRA_TRACE
ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnMenuChar\n"));
#endif
bHandled = TRUE;
T* pT = static_cast<T*>(this);
LRESULT lRet;
if(m_bMenuActive && LOWORD(wParam) != 0x0D)
lRet = 0;
else
lRet = MAKELRESULT(1, 1);
if(m_bMenuActive && HIWORD(wParam) == MF_POPUP)
{
// Convert character to lower/uppercase and possibly Unicode, using current keyboard layout
TCHAR ch = (TCHAR)LOWORD(wParam);
CMenuHandle menu = (HMENU)lParam;
int nCount = ::GetMenuItemCount(menu);
int nRetCode = MNC_EXECUTE;
BOOL bRet = FALSE;
TCHAR szString[pT->_nMaxMenuItemTextLength];
WORD wMnem = 0;
bool bFound = false;
for(int i = 0; i < nCount; i++)
{
CMenuItemInfo mii;
mii.cch = pT->_nMaxMenuItemTextLength;
mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE;
mii.dwTypeData = szString;
bRet = menu.GetMenuItemInfo(i, TRUE, &mii);
if(!bRet || (mii.fType & MFT_SEPARATOR))
continue;
_MenuItemData* pmd = (_MenuItemData*)mii.dwItemData;
if(pmd != NULL && pmd->IsCmdBarMenuItem())
{
LPTSTR p = pmd->lpstrText;
if(p != NULL)
{
while(*p && *p != _T('&'))
p = ::CharNext(p);
if(p != NULL && *p)
{
DWORD dwP = MAKELONG(*(++p), 0);
DWORD dwC = MAKELONG(ch, 0);
if(::CharLower((LPTSTR)ULongToPtr(dwP)) == ::CharLower((LPTSTR)ULongToPtr(dwC)))
{
if(!bFound)
{
wMnem = (WORD)i;
bFound = true;
}
else
{
nRetCode = MNC_SELECT;
break;
}
}
}
}
}
}
if(bFound)
{
if(nRetCode == MNC_EXECUTE)
{
PostMessage(TB_SETHOTITEM, (WPARAM)-1, 0L);
pT->GiveFocusBack();
}
bHandled = TRUE;
lRet = MAKELRESULT(wMnem, nRetCode);
}
}
else if(!m_bMenuActive)
{
int nBtn = 0;
if(!MapAccelerator((TCHAR)LOWORD(wParam), nBtn))
{
bHandled = FALSE;
PostMessage(TB_SETHOTITEM, (WPARAM)-1, 0L);
pT->GiveFocusBack();
#if (_WIN32_IE >= 0x0500)
// check if we should display chevron menu
if((TCHAR)LOWORD(wParam) == pT->_chChevronShortcut)
{
if(pT->DisplayChevronMenu())
bHandled = TRUE;
}
#endif // (_WIN32_IE >= 0x0500)
}
else if(m_wndParent.IsWindowEnabled())
{
#if (_WIN32_IE >= 0x0500)
RECT rcClient = { 0 };
GetClientRect(&rcClient);
RECT rcBtn = { 0 };
GetItemRect(nBtn, &rcBtn);
TBBUTTON tbb = { 0 };
GetButton(nBtn, &tbb);
if((tbb.fsState & TBSTATE_ENABLED) != 0 && (tbb.fsState & TBSTATE_HIDDEN) == 0 && rcBtn.right <= rcClient.right)
{
#endif // (_WIN32_IE >= 0x0500)
if(m_bUseKeyboardCues && !m_bShowKeyboardCues)
{
m_bAllowKeyboardCues = true;
ShowKeyboardCues(true);
}
pT->TakeFocus();
PostMessage(WM_KEYDOWN, VK_DOWN, 0L);
SetHotItem(nBtn);
#if (_WIN32_IE >= 0x0500)
}
else
{
::MessageBeep(0);
}
#endif // (_WIN32_IE >= 0x0500)
}
}
return lRet;
}
LRESULT OnDrawItem(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT)lParam;
_MenuItemData* pmd = (_MenuItemData*)lpDrawItemStruct->itemData;
if(lpDrawItemStruct->CtlType == ODT_MENU && pmd != NULL && pmd->IsCmdBarMenuItem())
{
T* pT = static_cast<T*>(this);
pT->DrawItem(lpDrawItemStruct);
}
else
{
bHandled = FALSE;
}
return (LRESULT)TRUE;
}
LRESULT OnMeasureItem(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
LPMEASUREITEMSTRUCT lpMeasureItemStruct = (LPMEASUREITEMSTRUCT)lParam;
_MenuItemData* pmd = (_MenuItemData*)lpMeasureItemStruct->itemData;
if(lpMeasureItemStruct->CtlType == ODT_MENU && pmd != NULL && pmd->IsCmdBarMenuItem())
{
T* pT = static_cast<T*>(this);
pT->MeasureItem(lpMeasureItemStruct);
}
else
{
bHandled = FALSE;
}
return (LRESULT)TRUE;
}
// API message handlers
LRESULT OnAPIGetMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
return (LRESULT)m_hMenu;
}
LRESULT OnAPITrackPopupMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
if(lParam == NULL)
return FALSE;
LPCBRPOPUPMENU lpCBRPopupMenu = (LPCBRPOPUPMENU)lParam;
if(lpCBRPopupMenu->cbSize != sizeof(CBRPOPUPMENU))
return FALSE;
T* pT = static_cast<T*>(this);
return pT->TrackPopupMenu(lpCBRPopupMenu->hMenu, lpCBRPopupMenu->uFlags, lpCBRPopupMenu->x, lpCBRPopupMenu->y, lpCBRPopupMenu->lptpm);
}
LRESULT OnAPIGetCmdBar(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
return (LRESULT)m_hWnd;
}
// Parent window message handlers
LRESULT OnParentHotItemChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
LPNMTBHOTITEM lpNMHT = (LPNMTBHOTITEM)pnmh;
// Check if this comes from us
if(pnmh->hwndFrom != m_hWnd)
{
bHandled = FALSE;
return 0;
}
bool bBlockTracking = false;
if((m_dwExtendedStyle & CBR_EX_TRACKALWAYS) == 0)
{
DWORD dwProcessID;
::GetWindowThreadProcessId(::GetActiveWindow(), &dwProcessID);
bBlockTracking = (::GetCurrentProcessId() != dwProcessID);
}
if((!m_wndParent.IsWindowEnabled() || bBlockTracking) && (lpNMHT->dwFlags & HICF_MOUSE))
{
return 1;
}
else
{
#ifndef HICF_LMOUSE
const DWORD HICF_LMOUSE = 0x00000080; // left mouse button selected
#endif
bHandled = FALSE;
// Send WM_MENUSELECT to the app if it needs to display a status text
if(!(lpNMHT->dwFlags & HICF_MOUSE)
&& !(lpNMHT->dwFlags & HICF_ACCELERATOR)
&& !(lpNMHT->dwFlags & HICF_LMOUSE))
{
if(lpNMHT->dwFlags & HICF_ENTERING)
m_wndParent.SendMessage(WM_MENUSELECT, 0, (LPARAM)m_hMenu);
if(lpNMHT->dwFlags & HICF_LEAVING)
m_wndParent.SendMessage(WM_MENUSELECT, MAKEWPARAM(0, 0xFFFF), NULL);
}
return 0;
}
}
LRESULT OnParentDropDown(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
// Check if this comes from us
if(pnmh->hwndFrom != m_hWnd)
{
bHandled = FALSE;
return 1;
}
T* pT = static_cast<T*>(this);
if(::GetFocus() != m_hWnd)
pT->TakeFocus();
LPNMTOOLBAR pNMToolBar = (LPNMTOOLBAR)pnmh;
int nIndex = CommandToIndex(pNMToolBar->iItem);
m_bContextMenu = false;
m_bEscapePressed = false;
pT->DoPopupMenu(nIndex, true);
return TBDDRET_DEFAULT;
}
LRESULT OnParentInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return OnInitMenuPopup(uMsg, wParam, lParam, bHandled);
}
LRESULT OnParentInternalGetBar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return OnInternalGetBar(uMsg, wParam, lParam, bHandled);
}
LRESULT OnParentSysCommand(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
bHandled = FALSE;
if((m_uSysKey == VK_MENU
|| (m_uSysKey == VK_F10 && !(::GetKeyState(VK_SHIFT) & 0x80))
|| m_uSysKey == VK_SPACE)
&& wParam == SC_KEYMENU)
{
T* pT = static_cast<T*>(this);
if(::GetFocus() == m_hWnd)
{
pT->GiveFocusBack(); // exit menu "loop"
PostMessage(TB_SETHOTITEM, (WPARAM)-1, 0L);
}
else if(m_uSysKey != VK_SPACE && !m_bSkipMsg)
{
if(m_bUseKeyboardCues && !m_bShowKeyboardCues && m_bAllowKeyboardCues)
ShowKeyboardCues(true);
pT->TakeFocus(); // enter menu "loop"
bHandled = TRUE;
}
else if(m_uSysKey != VK_SPACE)
{
bHandled = TRUE;
}
}
m_bSkipMsg = false;
return 0;
}
LRESULT OnParentAPIGetMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return OnAPIGetMenu(uMsg, wParam, lParam, bHandled);
}
LRESULT OnParentMenuChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return OnMenuChar(uMsg, wParam, lParam, bHandled);
}
LRESULT OnParentAPITrackPopupMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return OnAPITrackPopupMenu(uMsg, wParam, lParam, bHandled);
}
LRESULT OnParentAPIGetCmdBar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return OnAPIGetCmdBar(uMsg, wParam, lParam, bHandled);
}
LRESULT OnParentSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
OnSettingChange(uMsg, wParam, lParam, bHandled);
bHandled = FALSE;
return 1;
}
LRESULT OnParentDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return OnDrawItem(uMsg, wParam, lParam, bHandled);
}
LRESULT OnParentMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return OnMeasureItem(uMsg, wParam, lParam, bHandled);
}
LRESULT OnParentActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
m_bParentActive = (LOWORD(wParam) != WA_INACTIVE);
if(!m_bParentActive && m_bUseKeyboardCues && m_bShowKeyboardCues)
{
ShowKeyboardCues(false); // this will repaint our window
}
else
{
Invalidate();
UpdateWindow();
}
bHandled = FALSE;
return 1;
}
LRESULT OnParentCustomDraw(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
LRESULT lRet = CDRF_DODEFAULT;
bHandled = FALSE;
if(pnmh->hwndFrom == m_hWnd)
{
LPNMTBCUSTOMDRAW lpTBCustomDraw = (LPNMTBCUSTOMDRAW)pnmh;
if(lpTBCustomDraw->nmcd.dwDrawStage == CDDS_PREPAINT)
{
lRet = CDRF_NOTIFYITEMDRAW;
bHandled = TRUE;
}
else if(lpTBCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
if(m_bFlatMenus)
{
#ifndef COLOR_MENUHILIGHT
const int COLOR_MENUHILIGHT = 29;
#endif // !COLOR_MENUHILIGHT
bool bDisabled = ((lpTBCustomDraw->nmcd.uItemState & CDIS_DISABLED) == CDIS_DISABLED);
if(!bDisabled && ((lpTBCustomDraw->nmcd.uItemState & CDIS_HOT) == CDIS_HOT ||
(lpTBCustomDraw->nmcd.uItemState & CDIS_SELECTED) == CDIS_SELECTED))
{
::FillRect(lpTBCustomDraw->nmcd.hdc, &lpTBCustomDraw->nmcd.rc, ::GetSysColorBrush(COLOR_MENUHILIGHT));
::FrameRect(lpTBCustomDraw->nmcd.hdc, &lpTBCustomDraw->nmcd.rc, ::GetSysColorBrush(COLOR_HIGHLIGHT));
lpTBCustomDraw->clrText = ::GetSysColor(m_bParentActive ? COLOR_HIGHLIGHTTEXT : COLOR_GRAYTEXT);
}
else if(bDisabled || !m_bParentActive)
{
lpTBCustomDraw->clrText = ::GetSysColor(COLOR_GRAYTEXT);
}
CDCHandle dc = lpTBCustomDraw->nmcd.hdc;
dc.SetTextColor(lpTBCustomDraw->clrText);
dc.SetBkMode(lpTBCustomDraw->nStringBkMode);
HFONT hFont = GetFont();
HFONT hFontOld = NULL;
if(hFont != NULL)
hFontOld = dc.SelectFont(hFont);
const int cchText = 200;
TCHAR szText[cchText] = { 0 };
TBBUTTONINFO tbbi = { 0 };
tbbi.cbSize = sizeof(TBBUTTONINFO);
tbbi.dwMask = TBIF_TEXT;
tbbi.pszText = szText;
tbbi.cchText = cchText;
GetButtonInfo((int)lpTBCustomDraw->nmcd.dwItemSpec, &tbbi);
dc.DrawText(szText, -1, &lpTBCustomDraw->nmcd.rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER | (m_bShowKeyboardCues ? 0 : DT_HIDEPREFIX));
if(hFont != NULL)
dc.SelectFont(hFontOld);
lRet = CDRF_SKIPDEFAULT;
bHandled = TRUE;
}
else if(!m_bParentActive)
{
lpTBCustomDraw->clrText = ::GetSysColor(COLOR_GRAYTEXT);
bHandled = TRUE;
}
}
}
return lRet;
}
// Message hook handlers
LRESULT OnHookMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
static POINT s_point = { -1, -1 };
DWORD dwPoint = ::GetMessagePos();
POINT point = { GET_X_LPARAM(dwPoint), GET_Y_LPARAM(dwPoint) };
bHandled = FALSE;
if(m_bMenuActive)
{
if(::WindowFromPoint(point) == m_hWnd)
{
ScreenToClient(&point);
int nHit = HitTest(&point);
if((point.x != s_point.x || point.y != s_point.y) && nHit >= 0 && nHit < ::GetMenuItemCount(m_hMenu) && nHit != m_nPopBtn && m_nPopBtn != -1)
{
TBBUTTON tbb = { 0 };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -