void CXTPCustomizeMenusPage::OnSelectionChangedContextmenus() { CXTPCommandBars* pCommandBars = m_pSheet->GetCommandBars(); CommitContextMenu(); int nSel = m_cmbContextMenus.GetCurSel(); if (nSel < 1) { GetDlgItem(XTP_IDC_BUTTON_RESETCONTEXT)->EnableWindow(FALSE); return; } GetDlgItem(XTP_IDC_BUTTON_RESETCONTEXT)->EnableWindow(TRUE); CXTPPopupBar* pPopupBar = (CXTPPopupBar*)m_cmbContextMenus.GetItemData(nSel); CXTPToolBar* pContextMenu = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop, RUNTIME_CLASS(CXTPFloatingPopupBar)); if (!pContextMenu) { TRACE0("Failed to create toolbar\n"); return; } CXTPControls* pControls = pPopupBar->GetControls()->Duplicate(); pContextMenu->SetControls(pControls); pContextMenu->SetBarID(pPopupBar->GetBarID()); pContextMenu->SetTitle(pPopupBar->GetTitle()); pContextMenu->SetCustomizeDialogPresent(FALSE); pContextMenu->SetPosition(xtpBarFloating); pContextMenu->EnableDocking(xtpFlagFloating); pContextMenu->OnRecalcLayout(); CXTPWindowRect rcContext(pContextMenu); CXTPWindowRect rcParent(GetParent()); CPoint pt = m_ptContextMenu; if (pt == CPoint(0, 0)) pt = CPoint(rcParent.left - rcContext.Width(), rcParent.top); pContextMenu->MoveWindow(pt.x, pt.y, rcContext.Width(), rcContext.Height()); m_pContextMenu = pContextMenu; pContextMenu->SetCommandBarData((DWORD_PTR)pPopupBar); pContextMenu->OnUpdateCmdUI(); }
BOOL CXTPCustomizeMenusPage::OnInitDialog() { CXTPPropertyPage::OnInitDialog(); CXTPCommandBars* pCommandBars = m_pSheet->GetCommandBars(); CString strDefaultMenu; GetDlgItemText(XTP_IDC_STATIC_DESCRIPTION, strDefaultMenu); if (_tcschr(strDefaultMenu, _T('\n')) != NULL) { AfxExtractSubString(m_strDefaultMenuDesc, strDefaultMenu, 1); AfxExtractSubString(m_strDefaultMenu, strDefaultMenu, 0); } else { m_strDefaultMenu = m_strDefaultMenuDesc = strDefaultMenu; } int nIndex = m_cmbAppMenus.AddString(m_strDefaultMenu); m_cmbAppMenus.SetItemData(nIndex, 0); int nCurSel = 0; if (pCommandBars->GetMenuBar() && ((pCommandBars->GetMenuBar()->GetFlags() & xtpFlagIgnoreSetMenuMessage) == 0)) { CXTPMenuBar* pMenuBar = pCommandBars->GetMenuBar(); CXTPMenuBarMDIMenus* pMDIControls = pMenuBar->GetMDIMenus(); POSITION pos = pMDIControls->GetStartPosition(); CXTPMenuBarMDIMenuInfo* pInfo; while (pos) { pMDIControls->GetNextMenu(pos, pInfo); if (pInfo->m_nIDResource == pMenuBar->GetDefaultMenuResource()) continue; if (!pInfo->m_strTitle.IsEmpty()) { nIndex = m_cmbAppMenus.AddString(pInfo->m_strTitle); m_cmbAppMenus.SetItemData(nIndex, (DWORD_PTR)pInfo); if (pInfo->m_nIDResource == pMenuBar->GetCurrentMenuResource()) { nCurSel = nIndex; } } } } m_cmbAppMenus.SetCurSel(nCurSel); OnSelectionChangedAppmenus(); nIndex = m_cmbContextMenus.AddString(_T("")); m_cmbContextMenus.SetItemData(nIndex, 0); for (int i = 0; i < pCommandBars->GetContextMenus()->GetCount(); i++) { CXTPPopupBar* pPopupBar = (CXTPPopupBar*)pCommandBars->GetContextMenus()->GetAt(i); nIndex = m_cmbContextMenus.AddString(pPopupBar->GetTitle()); m_cmbContextMenus.SetItemData(nIndex, (DWORD_PTR)pPopupBar); } m_cmbContextMenus.SetCurSel(0); OnSelectionChangedContextmenus(); SetResize(XTP_IDC_STATIC_APPLICATIONMENUS, XTP_ANCHOR_TOPLEFT, XTP_ANCHOR_TOPRIGHT); SetResize(XTP_IDC_STATIC_CONTEXTMENUS, XTP_ANCHOR_TOPLEFT, XTP_ANCHOR_TOPRIGHT); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }