Exemple #1
0
void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd) 
{
	CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
	
	if (bActivate)
	{
		CMenu* pTopMenu = AfxGetMainWnd()->GetMenu();
		for(unsigned int i = 0; i < pTopMenu->GetMenuItemCount(); i++)
		{
			CMenu *pSubMenu = pTopMenu->GetSubMenu(i);
			if (pSubMenu)
				for(unsigned int j=0; j < pSubMenu->GetMenuItemCount(); j++)
				{
					if (pSubMenu->GetMenuItemID(j) == ID_PORTS_CREATE)
					{
						CMenu ResourceMenu;
						ResourceMenu.CreatePopupMenu();

						for(int k=0;k < Port::portCount() ; k++)
							ResourceMenu.AppendMenu(MF_STRING,ID_RESOURCE_PORT_BEGIN + k,
								Port::portName( k ) );

						pSubMenu->DeleteMenu(j,MF_BYPOSITION);
						pSubMenu->InsertMenu(j,MF_POPUP|MF_BYPOSITION,(unsigned int)ResourceMenu.Detach(),_T("Create"));

						return;
					}
				}
		}
	}
}
Exemple #2
0
CMenu 	*GetTemplateMenu()
{
    int iPos;
    CMenu* pViewMenu = NULL;
    CMenu* pTopMenu = AfxGetMainWnd()->GetMenu();

    for (iPos = pTopMenu->GetMenuItemCount()-1; iPos >= 0; iPos--)
    {
        CMenu* pMenu = pTopMenu->GetSubMenu(iPos);
        if (pMenu && pMenu->GetMenuItemID(0) == ID_VIEW_TOOLBAR)
        {
            pViewMenu = pMenu;
            break;
        }
    }
    ASSERT(pViewMenu != NULL);

    CMenu* pfMenu = NULL;
    for (iPos = pViewMenu->GetMenuItemCount()-1; iPos >= 0; iPos--)
    {
        pfMenu = pViewMenu->GetSubMenu(iPos);
        if(pfMenu)
            break;
    }
    ASSERT(pfMenu != NULL);
    return (pfMenu);
}
void CEsmRefCellPage::OnContextMenu(CWnd* pWnd, CPoint Point) {
  CMenu  Menu;
  CMenu* pPopup;
  BOOL   Result;
  CCmdUI MenuState;
  int    Index;

	/* Get the popup menu to display */
  Result = Menu.LoadMenu(IDR_CELLREF_MENU);
  if (!Result) return;
  pPopup = Menu.GetSubMenu(0);
  if (pPopup == NULL) return;

  	/* Force the update of the menu commands */
  for (Index = 0; Index < (int) pPopup->GetMenuItemCount(); Index++) {
    MenuState.m_nID = pPopup->GetMenuItemID(Index);
    MenuState.m_nIndex = Index;
    MenuState.m_pMenu = pPopup;
    MenuState.m_pOther = NULL;
    MenuState.m_pSubMenu = NULL;
    MenuState.m_nIndexMax = pPopup->GetMenuItemCount();

    if (MenuState.m_nID != 0) {
      OnCmdMsg(MenuState.m_nID, CN_UPDATE_COMMAND_UI, &MenuState, NULL);
     }
   }
  
  if (pWnd->GetDlgCtrlID() == IDC_OBJECTLIST) {
    pPopup->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN, Point.x, Point.y, this);
   }

 }
// 参看:http://www.cnblogs.com/hcfalan/archive/2010/11/24/1886139.html
BOOL CDlgImageViewer::ContinueModal()
{
	if(m_ToolBar.IsWindowVisible())
	{
		CFrameWnd* pParent = (CFrameWnd*)m_ToolBar.GetParent();
		if(pParent)
			m_ToolBar.OnUpdateCmdUI(pParent, (WPARAM)TRUE);
	}
	CMenu* pMainMenu = GetMenu();
	CCmdUI cmdUI;
	if (pMainMenu != NULL)
	{
		for (int n = 0; n < pMainMenu->GetMenuItemCount(); ++n)
		{
			CMenu* pSubMenu = pMainMenu->GetSubMenu(n);
			cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();
			for (int i = 0; i < cmdUI.m_nIndexMax; ++i)
			{
				cmdUI.m_nIndex = i;
				cmdUI.m_nID = pSubMenu->GetMenuItemID(i);
				cmdUI.m_pMenu = pSubMenu;
				cmdUI.DoUpdate(this, FALSE);
			}
		}
	}
	return CDialogEx::ContinueModal();
}
void CImageTreeCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
{
	// TODO: Add your message handler code here

	
	CPoint pt(point);
	ScreenToClient(&pt);
	UINT flags;
	HTREEITEM hItem = HitTest(pt, &flags);
	bool bOnItem = (flags & TVHT_ONITEM) != 0;

	CMenu add;
	VERIFY(add.CreatePopupMenu());
	if(bOnItem) {
		if(CanInsertItem(GetParentItem(hItem)))
			VERIFY(add.AppendMenu(MF_STRING, ID_ADD_SIBLING, _T("New Sibling\tINS")));
		if(CanInsertItem(hItem))
			VERIFY(add.AppendMenu(MF_STRING, ID_ADD_CHILD, _T("New Child Item\tCtrl+INS")));
	}
	if(CanInsertItem(0))
		VERIFY(add.AppendMenu(MF_STRING, ID_ADD_ROOT, _T("New Root Item\tShift+INS")));

	CMenu sort;
	VERIFY(sort.CreatePopupMenu());
	VERIFY(sort.AppendMenu(MF_STRING, ID_SORT_LEVEL, _T("Current Level\tCtrl+S")));
	VERIFY(sort.AppendMenu(MF_STRING, ID_SORT_LEVELANDBELOW, _T("Current Level And Below\tCtrl+Shift+S")));

	CMenu menu;
	VERIFY(menu.CreatePopupMenu());
	if(bOnItem) {
		if(CanEditLabel(hItem))
			VERIFY(menu.AppendMenu(MF_STRING, ID_RENAME, _T("Rename\tF2")));
		if(CanDeleteItem(hItem))
			VERIFY(menu.AppendMenu(MF_STRING, ID_DELETE, _T("Delete\tDEL")));
	}
	if(add.GetMenuItemCount() > 0)
		VERIFY(menu.AppendMenu(MF_POPUP, UINT(add.GetSafeHmenu()), _T("Add")));
	if(bOnItem) {
		if(menu.GetMenuItemCount() > 0)
			VERIFY(menu.AppendMenu(MF_SEPARATOR));
		VERIFY(menu.AppendMenu(MF_POPUP, UINT(sort.GetSafeHmenu()), _T("Sort")));
	}

	

	// maybe the menu is empty...
	if(menu.GetMenuItemCount() > 0)
		menu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
	

}
Exemple #6
0
void CHello2Dlg::OnLbnDblclkList4()
{
	// TODO: 在此添加控件通知处理程序代码
  CMenu   mainmenu;    
  mainmenu.LoadMenu(IDR_SELPROBE);

  CMenu *pM = mainmenu.GetSubMenu(0);
  //remove the existing menu
  CString   str ;  
  int i;
  for(i=pM->GetMenuItemCount()-1;i>=0;i--)   //取得菜单的项数。  
  {    
          pM->GetMenuString(i,str,MF_BYPOSITION);    
          //将指定菜单项的标签拷贝到指定的缓冲区。MF_BYPOSITION的解释见上。    
		  pM->DeleteMenu(i,MF_BYPOSITION);   
  }
  pM->AppendMenu(MF_STRING,ID_32771,_T("显示转换结果"));
  pM->AppendMenu(MF_STRING,ID_32771+1,_T("显示原始数据"));
  pM->AppendMenu(MF_STRING,ID_32771+2,_T("删除选中数据"));
  pM->AppendMenu(MF_STRING,ID_32771+3,_T("清空所有数据"));
  pM->AppendMenu(MF_STRING,ID_32771+4,_T("导出所有数据"));
  m_cmdbase = ID_32773;

  CRect rect;
  m_chlist.GetClientRect(&rect);
  
  CPoint pt;
  GetCursorPos(&pt);

    pM->TrackPopupMenu(TPM_LEFTALIGN,pt.x,pt.y,this);
	return;

}
Exemple #7
0
bool CDrawShapeView::showContextActions(const int* actions)
{
    CMenu menu;
    CMenu* popupMenu = NULL;

    if (actions && actions[0])
    {
        menu.LoadMenu(IDR_CONTEXTMENU);
        popupMenu = menu.GetSubMenu(0);

        int i, n = popupMenu->GetMenuItemCount();
        for (i = 0; i < n && actions[i] > 0; i++) {
            m_actions[i] = actions[i];
        }
        while (--n >= i) {
            m_actions[i] = 0;
            popupMenu->RemoveMenu(ID_DUMMY_1 + n, MF_BYCOMMAND);
        }
    }
    else
    {
        menu.LoadMenu(IDR_STEP1_VIEW);
        popupMenu = menu.GetSubMenu(1);
    }

    CPoint point(mgRound(m_proxy->motion.point.x), mgRound(m_proxy->motion.point.y));
    ClientToScreen(&point);

    return !!popupMenu->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN,
        point.x, point.y, GetParentFrame());
}
void CProcessManager::OnNMRClickList(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	

	CMenu	popup;
	popup.LoadMenu(IDR_PROCESS_MENU);               
	CMenu*	pM = popup.GetSubMenu(0);                 
	CPoint	p;
	GetCursorPos(&p);
	int	count = pM->GetMenuItemCount();

	if (m_List.GetSelectedCount() == 0)         
	{ 
		for (int i = 0;i<count;i++)
		{
			if(i!=2)
			{
				pM->EnableMenuItem(i, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);          
			}
		}

	}

	pM->TrackPopupMenu(TPM_LEFTALIGN, p.x, p.y, this);

	*pResult = 0;
}
Exemple #9
0
void CMenuSpawn::RemapMenu(HMENU hMenu)
{
	static int iRecurse = 0;
	iRecurse ++;

	CMenu pMenu;
	pMenu.Attach(hMenu);
	
	ASSERT(pMenu);
	int nItem = pMenu.GetMenuItemCount();
	while ((--nItem)>=0)
	{
		UINT itemId = pMenu.GetMenuItemID(nItem);
		if (itemId == (UINT) -1)
		{
			CMenu pops(pMenu.GetSubMenu(nItem));
			if (pops.GetHandleMenu()) RemapMenu(pops.GetHandleMenu());
			if (bIsPopup || iRecurse > 0)
			{
				TCHAR cs[128];
				memset(cs,0x00,128);
				pMenu.GetMenuString(nItem, cs, 128,MF_BYPOSITION);
				if (lstrlen(cs)>0)
				{
					SpawnItem * sp = AddSpawnItem(cs, (!bIsPopup && iRecurse == 1) ? -4 : -2);
					pMenu.ModifyMenu(nItem,MF_BYPOSITION|MF_OWNERDRAW, (UINT) -1, (LPCTSTR)sp);
				}
			}
		}
		else
		{
			if (itemId != 0)
			{
				UINT oldState = pMenu.GetMenuState(nItem,MF_BYPOSITION);
				if (!(oldState&MF_OWNERDRAW) && !(oldState&MF_BITMAP))
				{
					ASSERT(oldState != (UINT)-1);
					TCHAR cs[128];
					memset(cs,0x00,128);
					pMenu.GetMenuString(nItem, cs, 128, MF_BYPOSITION);
					SpawnItem * sp = AddSpawnItem(cs, itemId);
					if (itemId!=SC_CLOSE)
					pMenu.ModifyMenu(nItem,MF_BYPOSITION|MF_OWNERDRAW|oldState, (LPARAM)itemId, (LPCTSTR)sp);
				}
			}
			else
			{
				UINT oldState = pMenu.GetMenuState(nItem,MF_BYPOSITION);
				if (!(oldState&MF_OWNERDRAW) && !(oldState&MF_BITMAP))
				{
					ASSERT(oldState != (UINT)-1);
					SpawnItem * sp = AddSpawnItem("--", -3);
					pMenu.ModifyMenu(nItem,MF_BYPOSITION|MF_OWNERDRAW|oldState, (LPARAM)itemId, (LPCTSTR)sp);
				}
			}
		}
	}
	iRecurse --;
	pMenu.Detach();
}
void CCoolMenuBarCtrl::SetMenu(HMENU hMenu)
{
	m_hMenu = hMenu;
	
	Clear();
	
	if ( ! m_hMenu ) return;
	
	CMenu pMenu;
	pMenu.Attach( m_hMenu );
	
	for ( UINT nItem = 0 ; nItem < pMenu.GetMenuItemCount() ; nItem++ )
	{
		CString strMenu;
		pMenu.GetMenuString( nItem, strMenu, MF_BYPOSITION );
		
		int nAmp = strMenu.Find( '&' );
		if ( nAmp >= 0 ) strMenu = strMenu.Left( nAmp ) + strMenu.Mid( nAmp + 1 );
		
		CCoolBarItem* pItem = new CCoolBarItem( this, nItem + 1 );
		pItem->SetText( _T(" ") + strMenu + _T(" ") );
		m_pItems.AddTail( pItem );
	}
	
	pMenu.Detach();
}
Exemple #11
0
void CGh0stView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CListView::OnRButtonDown(nFlags, point);

	CMenu	popup;
	popup.LoadMenu(IDR_LIST);
	CMenu*	pM = popup.GetSubMenu(0);
	CPoint	p;
	GetCursorPos(&p);
	int	count = pM->GetMenuItemCount();
	if (m_pListCtrl->GetSelectedCount() == 0)
	{
		for (int i = 0; i < count - 2; i++)
		{
			pM->EnableMenuItem(i, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
		}
		pM->EnableMenuItem(count - 1, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);

	}
	
	// 全选
	if (m_pListCtrl->GetItemCount() > 0)
		pM->EnableMenuItem(count - 2, MF_BYPOSITION | MF_ENABLED);
	else
		pM->EnableMenuItem(count - 2, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
	
	pM->TrackPopupMenu(TPM_LEFTALIGN, p.x, p.y, this);
}
void CMainFrame::OnCwndDeletefilemenu()
{
   // This example deletes the leftmost popup menu or leftmost
   // popup menu item from the application's main window.
   CWnd* pMain = AfxGetMainWnd();

   // The main window _can_ be NULL, so this code
   // doesn't ASSERT and actually tests.
   if (pMain != NULL)
   {
      // Get the main window's menu
      CMenu* pMenu = pMain->GetMenu();

      // If there is a menu and it has items, we'll
      // delete the first one.
      if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
      {
         pMenu->DeleteMenu(0, MF_BYPOSITION);
         // force a redraw of the menu bar
         pMain->DrawMenuBar();
      }

      // No need to delete pMenu because it is an MFC
      // temporary object.
   }
}
BOOL COXShellNamespaceNavigator::InvokeDefaultCommand(const LPSHELLFOLDER lpParentFolder, 
													  const LPITEMIDLIST lpRelativeIDL) const
{
	// retrieve the default command ID
	HMENU hMenu=GetObjectContextMenu(lpParentFolder,lpRelativeIDL,CMF_DEFAULTONLY);
	if(hMenu==NULL)
	{
		TRACE(_T("COXShellNamespaceNavigator::InvokeDefaultCommand: GetObjectContextMenu() failed\n"));
		return FALSE;
	}

	CMenu menuPopup;
	VERIFY(menuPopup.Attach(hMenu));
	if(menuPopup.GetMenuItemCount()==0)
	{
		TRACE(_T("COXShellNamespaceNavigator::InvokeDefaultCommand: there is no context menu for the specified object\n"));
		return FALSE;
	}

	int nDefaultCmdID=-1;
#if _MFC_VER > 0x0421
	nDefaultCmdID=menuPopup.GetDefaultItem(GMDI_GOINTOPOPUPS,FALSE);
#else
	nDefaultCmdID=::GetMenuDefaultItem(menuPopup.GetSafeHmenu(),
		FALSE,GMDI_GOINTOPOPUPS);
#endif
	if(nDefaultCmdID==-1)
	{
		TRACE(_T("COXShellNamespaceNavigator::InvokeDefaultCommand: there is no default menu item for the specified object\n"));
		return FALSE;
	}
	VERIFY(menuPopup.DestroyMenu());

	return InvokeCommand(lpParentFolder,lpRelativeIDL,nDefaultCmdID,CMF_DEFAULTONLY);
}
Exemple #14
0
void CMainFrame::BuildViewList()
{
	WinGPAC *app = GetApp();
	if (!app->m_isopen) return;

	/*THIS IS HARCODED FROM THE MENU LAYOUT */
	CMenu *pMenu = GetMenu()->GetSubMenu(1)->GetSubMenu(0);
	while (pMenu->GetMenuItemCount()) pMenu->DeleteMenu(0, MF_BYPOSITION);

	s32 id = ID_VP_0;
	nb_viewpoints = 0;
	while (1) {
		const char *szName;
		Bool bound;
		M4Err e = M4T_GetViewpoint(app->m_term, nb_viewpoints+1, &szName, &bound);
		if (e) break;
		if (szName) {
			pMenu->AppendMenu(MF_ENABLED, id+nb_viewpoints, szName);
		} else {
			char szLabel[1024];
			sprintf(szLabel, "Viewpoint #%d", nb_viewpoints+1);
			pMenu->AppendMenu(MF_ENABLED, id+nb_viewpoints, szLabel);
		}
		nb_viewpoints++;
		if (nb_viewpoints==ID_VP_19-ID_VP_0) break;
	}
}
Exemple #15
0
void CHello2Dlg::OnStnDblclickRunGraph()
{
	// TODO: 在此添加控件通知处理程序代码
  CMenu   mainmenu;    
  mainmenu.LoadMenu(IDR_SELPROBE);
  m_graph.Invalidate();
  CMenu *pM = mainmenu.GetSubMenu(0);
  //remove the existing menu
  CString   str ;  
  int i;
  for(i=pM->GetMenuItemCount()-1;i>=0;i--)   //取得菜单的项数。  
  {    
          pM->GetMenuString(i,str,MF_BYPOSITION);    
          //将指定菜单项的标签拷贝到指定的缓冲区。MF_BYPOSITION的解释见上。    
		  pM->DeleteMenu(i,MF_BYPOSITION);   
  }
  pM->AppendMenu(MF_STRING,ID_32771,_T("关闭辅助显示"));
  for(i=0;i<sizeof(m_ridlgs)/sizeof(CRunitemDialog*);i++){
		CString name;
		name.Format(_T("同时显示通道%i"),i+1);
  		pM->AppendMenu(MF_STRING,ID_32771+1+i,name);
  }
  m_cmdbase = ID_32772;

  
  CPoint pt;
  GetCursorPos(&pt);
	SetForegroundWindow();
    pM->TrackPopupMenu(TPM_LEFTALIGN,pt.x,pt.y,this);
	return;
/*  CString tt;
  tt.Format(_T("clicked:%i,%i"),pt.x,pt.y);
  GetDlgItem(IDC_MAIN_STATUS)->SetWindowText(tt);
*/
}
Exemple #16
0
void MenuCreator::populatePluginMenu(std::string pluginId, PluginMenu item, IIdGenerator* idgenerator)
{
    int index = getParentMenuIndex(item.mParentMenu);
    if (-1 != index)
    {
        CMenu* menu = mMainMenu->GetSubMenu(index); //TODO::nullpointer check
        INT COUNT = menu->GetMenuItemCount();
for (auto itemMenu : item.menuList)
        {
            populateMenu(pluginId, menu, itemMenu, idgenerator);
        }
        COUNT = menu->GetMenuItemCount();
        CMenu* subMenu = menu->GetSubMenu(19);
        // COUNT = subMenu->GetMenuItemCount();
        COUNT++;
    }
}
Exemple #17
0
/******************************************************************************
Function Name  :  OnNMRclick
Input(s)       :
Output         :  void
Functionality  :
Member of      :  CTreeViewEx
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  30/03/2011
Modifications  :
******************************************************************************/
void CTreeViewEx::OnNMRclick(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{
    // TODO: Add your control notification handler code here
    CPoint point;
    GetCursorPos(&point);
    CPoint omCurrentPoint(point);
    ScreenToClient(&omCurrentPoint);
    UINT flags;
    HTREEITEM hItem = GetTreeCtrl().HitTest(omCurrentPoint, &flags);
    CTreeCtrl& omTempTreeCtrl = GetTreeCtrl();
    if(hItem && (flags & TVHT_ONITEM) && !(flags & TVHT_ONITEMRIGHT))
    {
        omTempTreeCtrl.SelectItem(hItem);
        eTYPE_ENTITY eEnityType = GetEditorWindow()->eGetCurrentEntityType();
        CMenu omContextMenu;

        VERIFY(omContextMenu.CreatePopupMenu());
        if(eEnityType == TEST_SETUP)
        {
            VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_ADD_TESTCASE, _("New Test Case")));
        }
        else if(eEnityType == TEST_CASE)
        {
            CMenu omSubMenu;
            omSubMenu.CreatePopupMenu();
            omSubMenu.AppendMenu(MF_STRING, IDM_ADD_SEND, _("Send"));
            omSubMenu.AppendMenu(MF_STRING, IDM_ADD_VERIFY, _("Verify"));
            omSubMenu.AppendMenu(MF_STRING, IDM_ADD_WAIT, _("Wait"));
            omSubMenu.AppendMenu(MF_STRING, IDM_ADD_VERIFYRESPONSE, _("verfiyResponse"));
            omSubMenu.AppendMenu(MF_STRING, IDM_ADD_VERIFYDLC, _("verifyDlc"));
            //omSubMenu.AppendMenu(MF_STRING, IDM_ADD_REPLAY, _T("Replay"));
            omContextMenu.AppendMenu(MF_POPUP, (UINT_PTR)omSubMenu.m_hMenu, _("New"));
            omContextMenu.AppendMenu(MF_STRING, IDM_DELETE, _("Delete"));
        }
        else
        {
            omContextMenu.AppendMenu(MF_STRING, IDM_DELETE, _("Delete"));
        }

        if(omContextMenu.GetMenuItemCount() > 0)
        {
            omContextMenu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
        }
        *pResult = 0;
    }

    else        //On Tree View Create Collapse All and Expand All
    {
        CMenu omContextMenu;
        VERIFY(omContextMenu.CreatePopupMenu());
        VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_COLLAPSE_ALL, _("Collapse All")));
        VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_EXPAND_ALL, _("Expand All")));
        VERIFY(omContextMenu.AppendMenu(MF_SEPARATOR));
        VERIFY(omContextMenu.AppendMenu(MF_STRING, IDM_SETTINGS_CLR, _("Background Color")));
        omContextMenu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
        *pResult = 0;
    }
}
Exemple #18
0
bool IEToolbar::onQuickLinksDropdown(const NMTOOLBAR& messageInfo, 
                                     LRESULT& lResult) {
  UNREFERENCED_PARAMETER(messageInfo);
  lResult = TBDDRET_DEFAULT;
  // if not logged on then dont allow to see menu
  if (!UserDataObserver::getInstance().isLoggedIn(false)) {
    UserDataObserver::getInstance().login();
  } else {
    // Prepare menu.
    CMenu menu;
    loadQuickLinksMenu(menu);
    CMenu* settingsSubMenu = menu.GetSubMenu(0);
    if (!settingsSubMenu) {
      throw Error("Failed to get quick links sub-menu\n");
    }

    //get all the menu items messages
    for (unsigned int index = 0; index < settingsSubMenu->GetMenuItemCount(); ++index) {
      ToolbarWindow::updateItem(settingsSubMenu, index);
    }
    // get the language popup submenu caption
    String message = ResourceMessages::getMessage(kToolbarMenuLanguage);
    settingsSubMenu->ModifyMenu(14, MF_BYPOSITION | MF_STRING, 0, message.c_str());

    // Set pop-up menu flags.
    const UINT trackFlags = TPM_LEFTALIGN | TPM_RIGHTBUTTON;

    // Calculate quick links button rect to show menu in appropriate position.
    CRect quickLinksButtonRect = toolbarWindow_.getItemRect(
        quickLinksButtonIndex_);
    toolbarWindow_.MapWindowPoints(0, quickLinksButtonRect);

   
    // get the language submenu
    buildLanguagesSubMenu(*settingsSubMenu);
    
    // Track pop-up menu.
    // Determine if MS Windows is right aligned and set x position
    // of the menu
    int x = isBiDi(LOCALE_SYSTEM_DEFAULT) ? quickLinksButtonRect.right :
      quickLinksButtonRect.left;
    const BOOL trackResult = settingsSubMenu->TrackPopupMenu(trackFlags,
      x, quickLinksButtonRect.bottom, &siteWindow_);
    if (FALSE == trackResult) {
      throw Error("Failed to track quick links menu\n");
    }

  }
  return true;
}
Exemple #19
0
void CCementBD::RenameMenuItem(UINT ID_menu_item, CString new_name)
{
    //---------------------------------------------------
    //Формируем меню внешних модулей
    CCementDoc* pDoc = (CCementDoc*)GetDocument();
    pDoc->m_DefaultMenu = 
        ::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_KRSCEMENTTYPE));
    if (pDoc->m_DefaultMenu == NULL)
        return;

    CMenu* menu = CMenu::FromHandle(pDoc->GetDefaultMenu());
    if(menu)
    {
        int iPos, iMaxPos, jPos, jMaxPos;
        CMenu *submenu = NULL;
		iMaxPos = (int)menu->GetMenuItemCount();
        for(iPos = 0; iPos < iMaxPos; iPos++)
        {
			submenu = menu->GetSubMenu(iPos);
			jMaxPos = (int)submenu->GetMenuItemCount();
			for(jPos = 0; jPos < jMaxPos; jPos++)
			{
				if(submenu->GetMenuItemID(jPos) == ID_menu_item) 
					break;
			}
			if (jPos < jMaxPos)
				break;
        }
        if(submenu == NULL || jPos >= jMaxPos || new_name.GetLength() == 0)
			return;
        BOOL flg = submenu->ModifyMenu(jPos, MF_BYPOSITION, ID_menu_item, new_name);
		//BOOL flg = submenu->ModifyMenu(ID_menu_item, MF_BYCOMMAND, ID_menu_item, new_name);
        CMDIFrameWnd* frame = ((CMDIChildWnd *) GetParent())->GetMDIFrame();
        frame->MDISetMenu(menu, NULL);
        frame->DrawMenuBar();
	}
}
Exemple #20
0
void CUserMeetingDlg::OnMyGroup()
{
	CMenu pMenu;
	pMenu.CreatePopupMenu();
	
	if ( m_pXML ) CreateMenuGroup( m_pXML, pMenu );
	
	HMENU hMenu = CreatePopupMenu();
	AppendMenu( pMenu, MF_STRING, MIN_GROUP - 1, _T("我的所有成员") );
	
	CRect rcButton;
	m_wndMember.GetWindowRect( &rcButton );
	
	DWORD nFlags = TPM_LEFTALIGN | TPM_VERTICAL | TPM_RIGHTBUTTON;
	
	if ( UINT nMenuID = pMenu.TrackPopupMenu(nFlags | TPM_RETURNCMD, rcButton.left, rcButton.bottom, this) )
	{
		if ( nMenuID == MIN_GROUP - 1 )
		{
			CString strText;
			m_wndGroup.GetWindowText( strText );
			
			CString str;
			str.Format( "是否发布\"%s\"内的所有成员?", strText );
			
			if (AfxMessageBox(str, MB_OKCANCEL | MB_ICONQUESTION | MB_DEFBUTTON2) == IDOK)
			{
				CMenu* pSubMenu = pMenu.GetSubMenu( pMenu.GetMenuItemCount() - 2 );
				if ( pSubMenu ) PutIntoPhone( pSubMenu->GetSafeHmenu(), 0, pSubMenu->GetMenuItemCount() );
			}
		}
		else
		{
			PutIntoPhone( pMenu, nMenuID );
		}
	}
}
Exemple #21
0
//Стандартный вызов ON_UPDATE_COMMAND_UI запрещает элементы меню, но не делает их grayed.
//Чтобы все таки запрещенные элементы меню выглядели как grayed, нужно вызывать эту функцию
//Note: эта функция не перерисовывает меню.
//Возвращает true - если произошли изменения и нужно перерисовать меню, иначе false
bool CMainFrame::_UpdateTopLevelMainMenu(void)
{
 CMenu* pMenu = this->GetMenu();
 std::vector<UINT> old_menu_state;

 //remember old states of all menu items
 {
  int menu_items_count = pMenu->GetMenuItemCount();
  for(int i = 0; i < menu_items_count; ++i)  
   old_menu_state.push_back(pMenu->GetMenuState(pMenu->GetMenuItemID(i),MF_BYCOMMAND));   
 }

 //Perform update
 CCmdUI ui;
 ui.m_nIndexMax = pMenu->GetMenuItemCount();
 ui.m_pMenu = pMenu;
 for (ui.m_nIndex = 0; ui.m_nIndex < ui.m_nIndexMax; ui.m_nIndex++) 
 {
  ui.m_nID = pMenu->GetMenuItemID(ui.m_nIndex);
  ui.DoUpdate(this, m_bAutoMenuEnable);
 }
 
 //Check: do we need to redraw menu?
 { 
  int menu_items_count = pMenu->GetMenuItemCount();
  for(int i = 0; i < menu_items_count; ++i)
  {
   UINT old_s = old_menu_state[i];
   UINT new_s = pMenu->GetMenuState(pMenu->GetMenuItemID(i),MF_BYCOMMAND);
   if (old_s!=new_s)   
    return true; //caller should redraw main menu   
  }
 }
 //nothing changed: redraw is not needed
 return false;
}
Exemple #22
0
int CChildView::GetMenuWidth()
{
    int width = 0;
    CMenu *menu = GetParentFrame()->GetMenu();
    int numItems = menu->GetMenuItemCount();

    for (int i = 0; i < numItems; i++) {
        CRect rect;

        GetMenuItemRect(*this, *menu, i, rect);
        width += rect.Width();
    }

    return width + GetSystemMetrics(SM_CXVSCROLL) + 1;
}
void DisplayView::PrepareCompatibleFiltersMenu(CMenu &menu, Pin *pin)
{
    /*
    	Enumerate output mediatypes and look for compatible
    	filters.
    */

    compatible_filters.filters.RemoveAll();

    // ignore invalid and connected pins
    if (!pin || !(pin->pin) || (pin->dir == PINDIR_INPUT)) return ;
    if (pin->connected) return ;

    // enumerate media types
    DSUtil::MediaTypes			mtypes;

    DSUtil::EnumMediaTypes(pin->pin, mtypes);
    if (mtypes.GetCount() <= 0) return ;

    // now try to enumerate compatible filters
    int ret = compatible_filters.EnumerateCompatible(mtypes, MERIT_UNLIKELY, false, render_params.exact_match_mode);
    if ((ret == 0) && (compatible_filters.filters.GetCount() > 0)) {

        CMenu		submenu;
        submenu.CreatePopupMenu();
        CMenu		&active_menu = submenu;

        for (int i=0; i<compatible_filters.filters.GetCount(); i++) {
            DSUtil::FilterTemplate	&filt = compatible_filters.filters[i];

            CString		merit;
            merit.Format(_T("%08x)"), filt.merit);
            merit = merit.MakeUpper();

            int idx = active_menu.GetMenuItemCount();

            CString		name = filt.name + _T("\t(0x") + merit;
            active_menu.InsertMenu(idx, MF_BYPOSITION | MF_STRING, ID_COMPATIBLE_FILTER + i, name);
        }

        // do insert the menu
        int		count = menu.GetMenuItemCount();
        menu.InsertMenu(count++, MF_BYPOSITION | MF_SEPARATOR);
        menu.InsertMenu(count, MF_BYPOSITION | MF_STRING, 0, _T("Compatible filters"));
        menu.ModifyMenu(count, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)submenu.m_hMenu, _T("Compatible filters"));
        submenu.Detach();
    }
}
void CMainFrame::OnClose() 
{
	if(m_pApp->m_iCurrentTasks>0)
	{
		AfxMessageBox("You have " + str(m_pApp->m_iCurrentTasks)+ " job(s) pending completion. Please wait for this to finish before closing.");
	}
	else
	{
		//disable close system menu.
		CMenu* pmenu = GetSystemMenu(FALSE);
		UINT size = pmenu->GetMenuItemCount( );
		pmenu->EnableMenuItem(pmenu->GetMenuItemID(6), MF_DISABLED | MF_GRAYED);
		DrawMenuBar();

		//instead of the 2 phase shutdown, i'm
		//just gonna risk leaking a little memory 
		//and simplify the code. markme saw a crash here.
		m_pApp->Terminate();
		
		//close the frame.
		CMDIFrameWnd::OnClose();

		//ALERT. Unusual code.
		//This is a 2phase shutdown to ensure we don't leak any memory due to floating msgs coming
		//in from the server.
		/*if(m_ShutDownPhase==0)
		{
			if(E_FAIL==m_pApp->Terminate())
			{
				//Terminate's already happened. Shutdown now.
				m_ShutDownPhase = 0;
				CMDIFrameWnd::OnClose();
				return;
			}
			m_ShutDownPhase=-23; //number same as below. number not used anywhere else.
			PostMessage(WM_CLOSE);
		}
		else if(m_ShutDownPhase==-23) //see number above.
		{
			m_ShutDownPhase = 0;
			CMDIFrameWnd::OnClose();
		}
		else
			ASSERT(0);
		*/
	}
}
//**************************************************************************************
void CBCGPTearOffManager::SetupTearOffMenus (HMENU hMenu)
{
	ASSERT (hMenu != NULL);

	CMenu* pMenu = CMenu::FromHandle (hMenu);
	if (pMenu == NULL)
	{
		return;
	}

	int iCount = (int) pMenu->GetMenuItemCount ();
	for (int i = 0; i < iCount; i ++)
	{
		UINT uiID = pMenu->GetMenuItemID (i);
		if (uiID != (UINT) -1)
		{
			continue;
		}

		UINT uiState = pMenu->GetMenuState (i, MF_BYPOSITION);
		if (uiState & MF_MENUBARBREAK)
		{
			CString str;
			pMenu->GetMenuString (i, str, MF_BYPOSITION);

			if (str [0] != cIDChar)
			{
				UINT uiCtrlBarId = GetFreeTearOffID ();
				if (uiCtrlBarId == 0)	// No more free IDs!
				{						// Reserve more IDs in Initialize!!!
					ASSERT (FALSE);
					return;
				}

				Build (uiCtrlBarId, str);
				pMenu->ModifyMenu (i, MF_BYPOSITION, i, str);
			}
		}

		CMenu* pPopupMenu = pMenu->GetSubMenu (i);
		if (pPopupMenu != NULL)
		{
			SetupTearOffMenus (pPopupMenu->GetSafeHmenu ());
		}
	}
}
//
// Find a statistic by its name (as stored in result file) and select it
// as though it had been selected from the menu.
// 
void CPageDisplay::SelectStatisticByName( int button, const char *statistic_name )
{
	unsigned int submenu_id, menu_item;

	if ( (button < 0) || (button >= NUM_STATUS_BARS) )
	{
		ErrorMessage("Invalid button value in CPageDisplay::SelectStatisticByName()");
		return;
	}
	if ( !statistic_name )
	{
		ErrorMessage("Invalid string in CPageDisplay::SelectStatisticByName()");
		return;
	}

	CMenu menu;
	VERIFY(menu.LoadMenu(IDR_POPUP_DISPLAY_LIST));

	CMenu* pPopup = menu.GetSubMenu(0);
	ASSERT(pPopup != NULL); // we can use ASSERT here because this should work every time if it works at all

	for ( submenu_id = 0; submenu_id < MDisplayNumSubmenus; submenu_id++ )
	{
		CMenu* pSubPopup = pPopup->GetSubMenu( submenu_id );
		if ( pSubPopup == NULL )
		{
			ErrorMessage("Could not get submenu in CPageDisplay::SelectStatisticByName()");
			return;
		}

		for ( menu_item = 0; menu_item < pSubPopup->GetMenuItemCount(); menu_item++ )
		{
			CString title;
			pSubPopup->GetMenuString( menu_item, title, MF_BYPOSITION );

			if ( title.CompareNoCase(statistic_name) == 0 )
			{
				selected_button = button;
				theApp.pView->OnMDisplay( submenu_id, pSubPopup->GetMenuItemID( menu_item ) );
				return;
			}
		}
	}
	// No match found, just leave the current selection unchanged
	return;
}
Exemple #27
0
void CViewMsgDlg::OnMenuQuickReply() 
{
#define IDM_QUICK_REPLY	1000
	
	CMenu menu;
	menu.CreatePopupMenu();

	IcqOption &options = icqLink->options;
	StrList l;
	IcqDB::loadQuickReply(l);
	StrList::iterator it;
	UINT id = IDM_QUICK_REPLY;

	CString str;
	for (it = l.begin(); it != l.end(); ++it) {
		CString str = (*it).c_str();
		if (str.GetLength() > 20)
			str = str.Left(20) + "...";
		menu.AppendMenu(
			str == options.quickReplyText.c_str() ? MF_CHECKED : MF_UNCHECKED,
			id++, str);
	}
	str.LoadString(IDS_QUICK_REPLY_SETTING);
	menu.AppendMenu(MF_STRING, id++, str);

	CRect rc;
	GetDlgItem(IDC_MENU_QUICK_REPLY)->GetWindowRect(rc);
	id = menu.TrackPopupMenu(TPM_RETURNCMD, rc.left, rc.bottom, this);
	if (id == 0)
		return;

	id -= IDM_QUICK_REPLY;
	if (id == menu.GetMenuItemCount() - 1)
		((CIcqDlg *) AfxGetMainWnd())->showOptions(1);
	else {
		int i = 0;
		for (it = l.begin(); it != l.end() && i < id; ++it, ++i)
			;
		if (it != l.end()) {
			options.quickReplyText = *it;
			IcqDB::saveOptions(options);
			OnQuickReply();
		}
	}
}
//****************************************************************************************
HMENU CBCGPToolbarSystemMenuButton::CreateMenu () const
{
	ASSERT (m_hSystemMenu != NULL);

	HMENU hMenu = CBCGPToolbarMenuButton::CreateMenu ();
	if (hMenu == NULL)
	{
		return NULL;
	}

	//---------------------------------------------------------------------
	// System menu don't produce updating command statuses via the
	// standard MFC idle command targeting. So, we should enable/disable
	// system menu items according to the standard system menu status:
	//---------------------------------------------------------------------
	CMenu* pMenu = CMenu::FromHandle (hMenu);
	ASSERT_VALID (pMenu);

	CMenu* pSysMenu = CMenu::FromHandle (m_hSystemMenu);
	ASSERT_VALID (pSysMenu);

	int iCount = (int) pSysMenu->GetMenuItemCount ();
	for (int i = 0; i < iCount; i ++)
	{
		UINT uiState = pSysMenu->GetMenuState (i, MF_BYPOSITION);
		UINT uiCmd = pSysMenu->GetMenuItemID (i);

		if (uiState & MF_CHECKED)
		{
			pMenu->CheckMenuItem (uiCmd, MF_CHECKED);
		}

		if (uiState & MF_DISABLED)
		{
			pMenu->EnableMenuItem (uiCmd, MF_DISABLED);
		}

		if (uiState & MF_GRAYED)
		{
			pMenu->EnableMenuItem (uiCmd, MF_GRAYED);
		}
	}

	return hMenu;
}
Exemple #29
0
void Languages::Translate(CMenu& menu)
{
    int count = menu.GetMenuItemCount();
    for(int i=0;i<count;i++)
    {
        CMenu* subMenu = menu.GetSubMenu(i);
        if(subMenu)
            Translate(*subMenu);
    }

    //set translated text for every know control ID
    for(int i=0;i<count;i++)
    {
        UINT id = menu.GetMenuItemID(i);
        CString szText;
        if(GetItemText(id, szText))
            VERIFY(menu.ModifyMenu(i, MF_BYPOSITION | MF_STRING, id, szText));
    }
}
BOOL SidebarWindow::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) {
    // we are interesting in catching TBN_DROPDOWN
    LPNMHDR notifyData = reinterpret_cast<LPNMHDR>(lParam);
    if (notifyData->code == TBN_DROPDOWN) {
        CMenu* sortSubMenu = sortMenu_.GetSubMenu(1);
        if (!sortSubMenu)
            throw Error("Failed to get sort submenu\n");

        //get all the menu items in the current culture
        for (unsigned int index = 0; index < sortSubMenu->GetMenuItemCount(); ++index) {
            ToolbarWindow::updateItem(sortSubMenu, index);
        }

        const UINT trackFlags = TPM_BOTTOMALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON;
        CRect sortButtonRect = settingsSortToolbar_.getItemRect(
                                   sortButtonIndex_);

        settingsSortToolbar_.MapWindowPoints(0, &sortButtonRect);

        sortSubMenu->CheckMenuRadioItem(ID_SORT_LAST_UPDATE_TIME, ID_SORT_NAME,
                                        sortModeToResID(activeSortMode_) , MF_BYCOMMAND);

        // Determine if MS Windows is right aligned and get position of the sort button
        // depending on it
        int x = isBiDi(LOCALE_SYSTEM_DEFAULT) ? sortButtonRect.right : sortButtonRect.left;
        const BOOL trackResult = sortSubMenu->TrackPopupMenu(trackFlags,
                                 x, sortButtonRect.top, this);

        if (FALSE == trackResult)
            throw Error("Failed to track sort menu\n");

        *pResult = TBDDRET_DEFAULT;

        return TRUE;
    }
    // catch the dynamic separator redraw
    if (notifyData->code == NM_CUSTOMDRAW) {
        return onToolbarCustomDraw((LPNMTBCUSTOMDRAW)(lParam),*pResult);
    }

    return CWnd::OnNotify(wParam, lParam, pResult);
}