BOOL NewGUI_SetIcon(BCMenu& rMenu, UINT uCommand, int nResourceID) { CString strMenuItemText; if(rMenu.GetMenuText(uCommand, strMenuItemText, MF_BYCOMMAND) == FALSE) return FALSE; if(strMenuItemText.GetLength() == 0) return FALSE; if(rMenu.ModifyODMenu(NULL, uCommand, nResourceID) == FALSE) return FALSE; return TRUE; }
void FileScrapDropDlg::OnInitMenuPopup(CMenu* pPopupMenu, xpr_uint_t nIndex, xpr_bool_t bSysMenu) { ASSERT(pPopupMenu != XPR_NULL); //super::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); // for multi-language BCMenu *pBCPopupMenu = dynamic_cast<BCMenu *>(pPopupMenu); if (pBCPopupMenu != XPR_NULL) { xpr_uint_t sId; xpr_sint_t sCount = pBCPopupMenu->GetMenuItemCount(); const xpr_tchar_t *sStringId; const xpr_tchar_t *sString; xpr::string sMenuText; CommandStringTable &sCommandStringTable = CommandStringTable::instance(); xpr_sint_t i; for (i = 0; i < sCount; ++i) { sId = pBCPopupMenu->GetMenuItemID(i); // apply string table if (sId != 0) // if sId is 0, it's separator. { if (sId == -1) { // if sId(xpr_uint_t) is -1, it's sub-menu. pBCPopupMenu->GetMenuText(i, sMenuText, MF_BYPOSITION); sString = gApp.loadString(sMenuText); pBCPopupMenu->SetMenuText(i, (xpr_tchar_t *)sString, MF_BYPOSITION); } else { sStringId = sCommandStringTable.loadString(sId); if (sStringId != XPR_NULL) { sString = gApp.loadString(sStringId); pBCPopupMenu->SetMenuText(sId, (xpr_tchar_t *)sString, MF_BYCOMMAND); } } } } } // Check the enabled state of various menu items. CCmdUI sState; sState.m_pMenu = pPopupMenu; ASSERT(sState.m_pOther == XPR_NULL); ASSERT(sState.m_pParentMenu == XPR_NULL); // Determine if menu is popup in top-level menu and set m_pOther to // it if so (m_pParentMenu == XPR_NULL indicates that it is secondary popup). HMENU sParentMenu; if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu) sState.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup. else if ((sParentMenu = ::GetMenu(m_hWnd)) != XPR_NULL) { CWnd *sParentWnd = this; // Child windows don't have menus--need to go to the top! if (sParentWnd != XPR_NULL && (sParentMenu = ::GetMenu(sParentWnd->m_hWnd)) != XPR_NULL) { xpr_sint_t sIndex; xpr_sint_t sIndexMax = ::GetMenuItemCount(sParentMenu); for (sIndex = 0; sIndex < sIndexMax; ++sIndex) { if (::GetSubMenu(sParentMenu, sIndex) == pPopupMenu->m_hMenu) { // When popup is found, m_pParentMenu is containing menu. sState.m_pParentMenu = CMenu::FromHandle(sParentMenu); break; } } } } sState.m_nIndexMax = pPopupMenu->GetMenuItemCount(); for (sState.m_nIndex = 0; sState.m_nIndex < sState.m_nIndexMax; ++sState.m_nIndex) { sState.m_nID = pPopupMenu->GetMenuItemID(sState.m_nIndex); if (sState.m_nID == 0) continue; // Menu separator or invalid cmd - ignore it. ASSERT(sState.m_pOther == XPR_NULL); ASSERT(sState.m_pMenu != XPR_NULL); if (sState.m_nID == (xpr_uint_t)-1) { // Possibly a popup menu, route to first item of that popup. sState.m_pSubMenu = pPopupMenu->GetSubMenu(sState.m_nIndex); if (sState.m_pSubMenu == XPR_NULL || (sState.m_nID = sState.m_pSubMenu->GetMenuItemID(0)) == 0 || sState.m_nID == (xpr_uint_t)-1) { continue; // First item of popup can't be routed to. } sState.DoUpdate(this, XPR_TRUE); // Popups are never auto disabled. } else { // Normal menu item. // Auto enable/disable if frame window has m_bAutoMenuEnable // set and command is _not_ a system command. sState.m_pSubMenu = XPR_NULL; sState.DoUpdate(this, XPR_FALSE); } // Adjust for menu deletions and additions. xpr_uint_t sCount = pPopupMenu->GetMenuItemCount(); if (sCount < sState.m_nIndexMax) { sState.m_nIndex -= (sState.m_nIndexMax - sCount); while (sState.m_nIndex < sCount && pPopupMenu->GetMenuItemID(sState.m_nIndex) == sState.m_nID) { sState.m_nIndex++; } } sState.m_nIndexMax = sCount; } }