void CMainFrame::AdjustObjectSubmenu (CMFCPopupMenu* pMenuPopup) { ASSERT (pMenuPopup != NULL); if (pMenuPopup == NULL) { return; } if (pMenuPopup->GetParentPopupMenu () != NULL) { return; } CMFCPopupMenuBar* pMenuBar = pMenuPopup->GetMenuBar (); ASSERT (pMenuBar != NULL); if (pMenuBar == NULL) { return; } int iIndex = pMenuBar->CommandToIndex (ID_OLE_VERB_POPUP); if (iIndex < 0) { return; } CWordPadDoc* pDoc = (CWordPadDoc*)GetActiveDocument(); ASSERT_VALID (pDoc); // check for single selection COleClientItem* pItem = pDoc->GetPrimarySelectedItem(GetActiveView()); if (pItem == NULL || pItem->GetType() == OT_STATIC) { // no selection, or is 'static' item return; } // only include Convert... if there is a handler for ID_OLE_EDIT_CONVERT UINT nConvertID = ID_OLE_EDIT_CONVERT; AFX_CMDHANDLERINFO info; if (!pDoc->OnCmdMsg(ID_OLE_EDIT_CONVERT, CN_COMMAND, NULL, &info)) nConvertID = 0; HMENU hMenu = pMenuBar->ExportToMenu (); ASSERT(hMenu != NULL); if (hMenu != NULL) { // update the menu AfxOleSetEditMenu(pItem, CMenu::FromHandle (hMenu), iIndex, ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, nConvertID); pMenuBar->ImportFromMenu (hMenu); ::DestroyMenu (hMenu); } }
void CMainFrame::AdjustColorsMenu (CMFCPopupMenu* pMenuPopup, UINT uiID) { CMFCPopupMenuBar* pMenuBar = pMenuPopup->GetMenuBar (); ASSERT (pMenuBar != NULL); if (pMenuBar == NULL) { return; } int iIndex = pMenuBar->CommandToIndex (uiID); if (iIndex < 0) { return; } if (DYNAMIC_DOWNCAST (CMFCColorMenuButton, pMenuBar->GetButton (iIndex)) != NULL) { return; } CMFCColorMenuButton* pColorButton = m_wndFormatBar.CreateColorButton (); pMenuBar->ReplaceButton (ID_CHAR_COLOR, *pColorButton, TRUE); delete pColorButton; }
void CMainFrame::AdjustObjectSubmenu(CMFCPopupMenu* pMenuPopup) { ASSERT(pMenuPopup != NULL); if (pMenuPopup->GetParentPopupMenu() != NULL) { return; } // <snippet7> // CMFCPopupMenu* pMenuPopup CMFCPopupMenuBar* pMenuBar = pMenuPopup->GetMenuBar(); // </snippet7> ASSERT(pMenuBar != NULL); // <snippet10> // CMFCPopupMenuBar* pMenuBar CMFCCustomizeMenuButton* pBtn = (CMFCCustomizeMenuButton*)pMenuBar->GetButton(0); pBtn->EnableCustomization(true); pBtn->SetSeparator(); // </snippet10> int iIndex = pMenuBar->CommandToIndex(ID_OLE_VERB_FIRST); if (iIndex < 0) { return; } CFrameWnd* pFrame = GetActiveFrame(); if (pFrame == NULL) { return; } CDrawDoc* pDoc = (CDrawDoc*)pFrame->GetActiveDocument(); ASSERT_VALID(pDoc); // check for single selection COleClientItem* pItem = pDoc->GetPrimarySelectedItem(pFrame->GetActiveView()); if (pItem == NULL || pItem->GetType() == OT_STATIC) { // no selection, or is 'static' item return; } // only include Convert... if there is a handler for ID_OLE_EDIT_CONVERT UINT nConvertID = ID_OLE_EDIT_CONVERT; AFX_CMDHANDLERINFO info; if (!pDoc->OnCmdMsg(ID_OLE_EDIT_CONVERT, CN_COMMAND, NULL, &info)) nConvertID = 0; HMENU hMenu = pMenuBar->ExportToMenu(); ASSERT(hMenu != NULL); // update the menu AfxOleSetEditMenu(pItem, CMenu::FromHandle(hMenu), iIndex, ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, nConvertID); pMenuBar->ImportFromMenu(hMenu); ::DestroyMenu(hMenu); }