Article ID: 200854
Article Last Modified on 11/21/2006
// CContainerCntrItem is a COleClientItem-derived class.
void CContainerCntrItem:OnInsertMenus(
CMenu* pMenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
{
((CContainerApp *) AfxGetApp())->m_hSharedMenu =
pMenuShared->GetSafeHmenu();
COleClientItem::OnInsertMenus(pMenuShared, lpMenuWidths);
}
void CContainerCntrItem::OnRemoveMenus(CMenu* pMenuShared)
{
((CContainerApp *) AfxGetApp())->m_hSharedMenu = NULL;
COleClientItem::OnRemoveMenus(pMenuShared);
}
// CContainerApp is a CWinApp-derived class.
BOOL CContainerApp::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_COMMAND && m_hSharedMenu)
{
// The drop-down menu in the menu bar is 0-based. To simplify the
// code, we make an assumption that the Edit menu is at position
// one, instead of looping through the main menu to find out the
// position of the Edit menu.
char str[80];
::GetMenuString(m_hSharedMenu, 1, str, sizeof(str),
MF_BYPOSITION);
TRACE("submenu = %s\n", str);
HMENU hsub = ::GetSubMenu(m_hSharedMenu, 1);
// Get the menu string of the selected menu item.
::GetMenuString(hsub, pMsg->wParam, str, sizeof(str),
MF_BYCOMMAND);
TRACE("menu item = %s\n", str);
// Do something when Edit\Paste menu command is selected.
if (lstrcmp(str, "&Paste\tCtrl+V") == 0)
TRACE("Word's Edit\\Paste menu command is selected\n");
return TRUE;
}
else
return CWinApp::PreTranslateMessage(pMsg);
}
Keywords: kbarchitecture kbcontainer kbhowto kbmenu KB200854