CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    37

    To get all the items in the menu and know if the menu item is disabled or enabled

    Hi,

    In a tree control, I would like to find out programatically if context menu would be displayed on right clicking a particular node. If any menu is displayed, then I should be able to get all the items in the menu and know if the menu item is disabled or enabled.

    How can this be done?

    regards,
    Kalpu

  2. #2
    Join Date
    Apr 2004
    Posts
    17
    hi,
    yes, you can display a context menu by right click over the tree
    control and then you can interate trough all the menu items and see which one is enabled or vice versa
    in MFC you only need an object from type CMenu

    you need:
    GetMenuItemCount
    GetMenuString
    GetMenuState

    you can open context menu on right mouse click over the tree like this (you need to have one menu already and name it IDR_MENU1 for example):
    Code:
    void CMyProjectDlg::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    	CMenu menu;   
    	if (!menu.LoadMenu(IDR_MENU1))      		
    		return;
    	CMenu* pSubMenu = menu.GetSubMenu(0);
    	if (!pSubMenu)       
    		return;
    
    	CPoint mouse;      
    	GetCursorPos(&mouse);      
    	::SetForegroundWindow(this->m_hWnd);
    	::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0, this->m_hWnd, NULL);					
    
    	
    	*pResult = 0;
    }
    hope this helps,
    regards,
    typecast

  3. #3
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    Originally posted by typecast
    yes, you can display a context menu by right click over the tree
    control
    Originally posted by kalpu
    I would like to find out programatically if context menu would be displayed on right clicking a particular node. If any menu is displayed, then I should be able to ...
    Originally posted by typecast
    yes, you can display a context menu by right click over the tree
    control
    I think question was not about how to display menu but detecting if menu is to be displayed.

    Kalpu, handle WM_INITMENUPOPUP message. See MSDN for details.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured