CXTPControl* CXTPRibbonGroup::FindControl(XTPControlType type, int nId, BOOL bVisible, BOOL bRecursive) const { for (int nIndex = 0; nIndex < GetCount(); nIndex++) { CXTPControl* pControl = GetAt(nIndex); if ((type == xtpControlError || pControl->GetType() == type) && (!bVisible || pControl->IsVisible()) && (nId == -1 || nId == pControl->GetID())) return pControl; if (bRecursive) { CXTPCommandBar* pBar = pControl->GetCommandBar(); if (pBar) { pControl = pBar->GetControls()->FindControl(type, nId, bVisible, bRecursive); if (pControl != NULL) return pControl; } } } return NULL; }
///////////////////////////////////////////////////////////////////////////// // 加载扩展菜单 ///////////////////////////////////////////////////////////////////////////// BOOL CPlugIn::AddOwmSubMenu(CString strMainMenu, CString strSubMenu, CString strAction) { CMainFrame* pMainFrame = (CMainFrame*)(theApp.GetMainWnd()); CXTPCommandBars* pCommandBars = pMainFrame->GetCommandBars(); if(!pCommandBars) { return FALSE; } CXTPCommandBar* pMenuBar = pCommandBars->GetMenuBar(); if(!pMenuBar) { return FALSE; } CXTPControls* pControls = pMenuBar->GetControls(); CXTPControl* pControl = pControls->GetFirst(); CXTPCommandBar* pMenuBarSub = NULL; CXTPControl* pControlExtSub = NULL; while(pControl) { if(pControl->GetCaption() == strMainMenu) { pMenuBarSub = pControl->GetCommandBar(); CXTPControls* pControlsSub = pMenuBarSub->GetControls(); pControl = pControlsSub->GetFirst(); while(pControl) { if(pControl->GetCaption() == strSubMenu) { pControlExtSub = pControl; break; } pControlsSub->GetNext(pControl); } break; } pControls->GetNext(pControl); } if(pMenuBarSub && !pControlExtSub) { CExtMenuInfo extMenuInfo; extMenuInfo.m_strVciId = m_strId; extMenuInfo.m_strMainMenu = strMainMenu; extMenuInfo.m_strSubMenu = strSubMenu; extMenuInfo.pProc = (TYPEOF_ClientMenu*)OnOwmExtMenuProc; extMenuInfo.pUpdateProc = NULL; extMenuInfo.nProcType = MENU_PROC_TYPE_PARAM_ID; int nExMenuId = IDM_OWMCMD+g_nIdOwmExMenu; extMenuInfo.m_strAction = strAction; extMenuInfo.nId = nExMenuId-IDM_OWMCMD; pMainFrame->m_arExtMenuInfo.Add(extMenuInfo); CXTPControls* pControlsSub = pMenuBarSub->GetControls(); CMenu* pMenu = new CMenu(); pMenu->CreatePopupMenu(); pMenu->AppendMenu(MF_STRING, nExMenuId, strSubMenu); pControlsSub->AddMenuItem(pMenu, 0); delete pMenu; g_nIdOwmExMenu++; } return TRUE; }