//************************************************************************************ BOOL CBCGPShowAllButton::OnClick (CWnd* /*pWnd*/, BOOL bDelay) { CBCGPPopupMenuBar* pParentMenuBar = DYNAMIC_DOWNCAST (CBCGPPopupMenuBar, m_pWndParent); if (pParentMenuBar == NULL) { ASSERT (FALSE); return FALSE; } if (bDelay) { if (CBCGPMenuBar::IsShowAllCommandsDelay ()) { pParentMenuBar->StartPopupMenuTimer (this, 2); } return TRUE; } CBCGPPopupMenu* pParentMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, pParentMenuBar->GetParent ()); if (pParentMenu == NULL) { ASSERT (FALSE); return FALSE; } pParentMenu->ShowAllCommands (); return TRUE; }
BOOL CMainFrame::OnShowMDITabContextMenu (CPoint point, DWORD dwAllowedItems, BOOL bDrop) { CMenu menu; VERIFY(menu.LoadMenu (bDrop ? IDR_POPUP_DROP_MDITABS : IDR_POPUP_MDITABS)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); if ((dwAllowedItems & BCGP_MDI_CREATE_HORZ_GROUP) == 0) { pPopup->DeleteMenu (ID_MDI_NEW_HORZ_TAB_GROUP, MF_BYCOMMAND); } if ((dwAllowedItems & BCGP_MDI_CREATE_VERT_GROUP) == 0) { pPopup->DeleteMenu (ID_MDI_NEW_VERT_GROUP, MF_BYCOMMAND); } if ((dwAllowedItems & BCGP_MDI_CAN_MOVE_NEXT) == 0) { pPopup->DeleteMenu (ID_MDI_MOVE_TO_NEXT_GROUP, MF_BYCOMMAND); } if ((dwAllowedItems & BCGP_MDI_CAN_MOVE_PREV) == 0) { pPopup->DeleteMenu (ID_MDI_MOVE_TO_PREV_GROUP, MF_BYCOMMAND); } CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu; pPopupMenu->SetAutoDestroy (FALSE); pPopupMenu->Create (this, point.x, point.y, pPopup->GetSafeHmenu ()); return TRUE; }
/** * @brief 响应鼠标在震源网格中右键消息,显示右键菜单 * @note 如果选中某一个震源,则响应消息,显示右键菜单。菜单内容包括停止某一震源、为震源分配炮点编号、 为某震源通过震源点测线号及道号来确定炮点、清除Ready状态等 * @param CWnd* pWnd,窗口指针 * @param CPoint point,鼠标坐标 * @return void */ void CActiveSourceWnd::OnContextMenu(CWnd* pWnd, CPoint point) { // TODO: 在此处添加消息处理程序代码 CBCGPGridCtrl* pGridCtrl = GetGridCtrl(); if(NULL==pGridCtrl) return; // 如果没有选择震源或者网格中某一行,则不弹出菜单 CBCGPGridRow* pRow= pGridCtrl->GetCurSel(); if(NULL==pRow) return; CMenu menu; // 加载右击菜单 VERIFY(menu.LoadMenu (IDR_POPUP_ACTIVESOURCE)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); // CMainFrame* pFrm = (CMainFrame*)AfxGetMainWnd(); CString strTemp; // 每一行的数据等于震源的编号 strTemp.Format(_T("Source %d"),pRow->GetData()); // pPopup->ModifyMenu(MF_BYCOMMAND,MF_STRING,ID_ACTIVESOURCE_SOURCE,strTemp); // pPopup->ModifyMenu(MF_BYPOSITION,MF_STRING,0,_T("AAAAA")); // 更改第一个菜单的标题,显示为“Source”+震源编号 MENUITEMINFO info; info.cbSize = sizeof (MENUITEMINFO); // must fill up this field info.fMask = MIIM_STRING; // get the state of the menu item info.dwTypeData = strTemp.GetBuffer(); info.cch = strTemp.GetLength(); VERIFY(pPopup->SetMenuItemInfo(ID_ACTIVESOURCE_SOURCE, &info,FALSE)); strTemp.ReleaseBuffer(); /* int nSourceState = pRow->GetItem(0)->GetImage(); if(nSourceState==SHOTSOURCE_FOCUS) { info.cbSize = sizeof (MENUITEMINFO); // must fill up this field info.fMask = MIIM_STATE; info.fState = MFS_DISABLED; // 如果正处于采集过程中,禁止更改放炮点 pPopup->SetMenuItemInfo(ID_ACTIVESOURCE_DISASSOCIATEVP, &info,FALSE); pPopup->SetMenuItemInfo(ID_ACTIVESOURCE_ASSOCIATEVP, &info,FALSE); pPopup->SetMenuItemInfo(ID_ACTIVESOURCE_ASSOCIATESPLSPN, &info,FALSE); // pPopup->EnableMenuItem(ID_ACTIVESOURCE_DISASSOCIATEVP,MF_BYCOMMAND|MF_DISABLED); // pPopup->EnableMenuItem(ID_ACTIVESOURCE_ASSOCIATEVP,MF_BYCOMMAND|MF_DISABLED); // pPopup->EnableMenuItem(ID_ACTIVESOURCE_ASSOCIATESPLSPN,MF_BYCOMMAND|MF_DISABLED); }*/ CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu; pPopupMenu->Create(this, point.x, point.y,pPopup->Detach(),FALSE,TRUE); }
LRESULT CMainFrame::OnToolbarContextMenu(WPARAM,LPARAM lp) { CPoint point (BCG_GET_X_LPARAM(lp), BCG_GET_Y_LPARAM(lp)); CMenu menu; VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu; pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ()); return 0; }
LRESULT CMainFrame::OnToolbarContextMenu(WPARAM wp,LPARAM lp) { CBCGPToolBar* pToolBar = DYNAMIC_DOWNCAST (CBCGPToolBar, CWnd::FromHandlePermanent ((HWND) wp)); m_bMainToolbarMenu = ( pToolBar != NULL && pToolBar->GetDlgCtrlID () == AFX_IDW_TOOLBAR); CPoint point (BCG_GET_X_LPARAM(lp), BCG_GET_Y_LPARAM(lp)); CMenu menu; VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu; pPopupMenu->Create (this, point.x, point.y, pPopup->Detach ()); return 0; }
//******************************************************************************************* BOOL CBCGPDlgImpl::ProcessMouseClick (POINT pt) { if (!CBCGPToolBar::IsCustomizeMode () && CBCGPPopupMenu::GetActiveMenu() != NULL && ::IsWindow (CBCGPPopupMenu::GetActiveMenu()->m_hWnd)) { CBCGPPopupMenu::MENUAREA_TYPE clickArea = CBCGPPopupMenu::GetActiveMenu()->CheckArea (pt); if (clickArea == CBCGPPopupMenu::OUTSIDE) { // Click outside of menu //-------------------------------------------- // Maybe secondary click on the parent button? //-------------------------------------------- CBCGPToolbarMenuButton* pParentButton = CBCGPPopupMenu::GetActiveMenu()->GetParentButton (); if (pParentButton != NULL) { CWnd* pWndParent = pParentButton->GetParentWnd (); if (pWndParent != NULL) { CBCGPPopupMenuBar* pWndParentPopupMenuBar = DYNAMIC_DOWNCAST (CBCGPPopupMenuBar, pWndParent); CPoint ptClient = pt; pWndParent->ScreenToClient (&ptClient); if (pParentButton->Rect ().PtInRect (ptClient)) { //------------------------------------------------------- // If user clicks second time on the parent button, // we should close an active menu on the toolbar/menubar // and leave it on the popup menu: //------------------------------------------------------- if (pWndParentPopupMenuBar == NULL && !CBCGPPopupMenu::GetActiveMenu()->InCommand ()) { //---------------------------------------- // Toolbar/menu bar: close an active menu! //---------------------------------------- CBCGPPopupMenu::GetActiveMenu()->SendMessage (WM_CLOSE); } return TRUE; } if (pWndParentPopupMenuBar != NULL) { pWndParentPopupMenuBar->CloseDelayedSubMenu (); CBCGPPopupMenu* pWndParentPopupMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, pWndParentPopupMenuBar->GetParent ()); if (pWndParentPopupMenu != NULL) { CBCGPPopupMenu::MENUAREA_TYPE clickAreaParent = pWndParentPopupMenu->CheckArea (pt); switch (clickAreaParent) { case CBCGPPopupMenu::MENU: case CBCGPPopupMenu::TEAROFF_CAPTION: case CBCGPPopupMenu::LOGO: return FALSE; case CBCGPPopupMenu::SHADOW_RIGHT: case CBCGPPopupMenu::SHADOW_BOTTOM: pWndParentPopupMenu->SendMessage (WM_CLOSE); m_Dlg.SetFocus (); return TRUE; } } } } } if (!CBCGPPopupMenu::GetActiveMenu()->InCommand ()) { CBCGPPopupMenu::GetActiveMenu()->SendMessage (WM_CLOSE); CWnd* pWndFocus = CWnd::GetFocus (); if (pWndFocus != NULL && pWndFocus->IsKindOf (RUNTIME_CLASS (CBCGPToolBar))) { m_Dlg.SetFocus (); } if (clickArea != CBCGPPopupMenu::OUTSIDE) // Click on shadow { return TRUE; } } } else if (clickArea == CBCGPPopupMenu::SHADOW_RIGHT || clickArea == CBCGPPopupMenu::SHADOW_BOTTOM) { CBCGPPopupMenu::GetActiveMenu()->SendMessage (WM_CLOSE); m_Dlg.SetFocus (); return TRUE; } } return FALSE; }
//************************************************************************************************ void CBCGPMenuPage::OnSelchangeContextMenuList() { m_wndResetMenuButton.EnableWindow (FALSE); if (g_pContextMenuManager == NULL) { return; } m_uiContextMenuResId = 0; //---------------------------------------- // First, save and close the current menu: //---------------------------------------- if (m_pContextMenu != NULL) { SaveMenu (); CBCGPPopupMenu* pMenu = m_pContextMenu; m_pContextMenu = NULL; pMenu->SendMessage (WM_CLOSE); } if (m_wndContextMenus.GetCurSel () <= 0) { //-------------------------------------- // No is menu selected, nothing to do... //-------------------------------------- return; } UpdateData (); HMENU hMenu = g_pContextMenuManager->GetMenuByName ( m_strContextMenuName, &m_uiContextMenuResId); if (hMenu == NULL) { MessageBeep ((UINT) -1); return; } HMENU hmenuPopup = ::GetSubMenu (hMenu, 0); if (hmenuPopup == NULL) { ASSERT (FALSE); return; } m_pContextMenu = new CBCGPPopupMenu (this, m_strContextMenuName); ASSERT (m_pContextMenu != NULL); if (!globalData.bIsWindowsNT4) { m_pContextMenu->SetAutoDestroy (FALSE); } if (!m_pContextMenu->Create (GetTopLevelFrame (), m_ptMenuLastPos.x, m_ptMenuLastPos.y, hmenuPopup)) { AfxMessageBox (_T("Can't create context menu!")); } else { m_wndResetMenuButton.EnableWindow (); } }