CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    Dynamic Popup Menus

    I am trying to create a context menu that lists all the buttons for each toolbar using popup submenus... something like this...

    File>
    ___New
    ___Open
    ___Save
    Edit>
    ___Cut
    ___Copy
    ___Paste
    etc...

    I create a popup menu like this...

    Code:
    CMenu menu;
    VERIFY(menu.LoadMenu(IDR_TOOLBAR_POPUP_MENU));
    
    // pPopupMenu is the highest level of my context menu...
    CMenu* pPopupMenu = menu.GetSubMenu(0);
    if (pPopupMenu)
    {
    	CString cstr;
    	m_wndFileToolBar.GetWindowText(cstr);
    	bool bSuccess = pPopupMenu->InsertMenu(0, MF_BYPOSITION | MF_ENABLED, MF_POPUP, cstr);
    	CMenu* pSubMenu1 = pPopupMenu->GetSubMenu(0);
    
    ///////////////// pSubMenu1 is NULL at this point ... What am I doing wrong???
    }
    I am trying to get a pointer to the newly created popup "submenu" so I can add menu items to it to represent each button from the toolbar...

  2. #2
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    Re: Dynamic Popup Menus

    I figured it out...

    Code:
    CMenu menu;
    VERIFY(menu.LoadMenu(IDR_TOOLBAR_POPUP_MENU));
    
    // pPopupMenu is the highest level of my context menu...
    CMenu* pPopupMenu = menu.GetSubMenu(0);
    if (pPopupMenu)
    {
    	// create the new popup menu
    	CMenu menuFile;
    	VERIFY(menuFile.CreatePopupMenu());
    
    	// add items to the new popup menu
    	menuFile.AppendMenu(MF_STRING, ID_TOOLBAR_BUTTON_BASE, (LPCTSTR)"New");
    
    // ...etc...
    
    	// get the title of the new popup menu
    	CString cstr;
    	m_wndFileToolBar.GetWindowText(cstr);
    
    	// add the NEW popup menu to the higherlevel popup menu
    	pPopupMenu->AppendMenu(MF_POPUP, (UINT) menuFile.m_hMenu, cstr);
    
    	// display the menu
    	pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pMsg->pt.x, pMsg->pt.y, this);
    }

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Dynamic Popup Menus

    Quote Originally Posted by sford View Post
    I figured it out...
    Good!
    Now you might want to mark this thread as [Resolved]
    Victor Nijegorodov

  4. #4
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    Re: Dynamic Popup Menus

    Thanks Victor! I am not sure how I go about marking the thread as Resolved...

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Dynamic Popup Menus

    FAQ
    Victor Nijegorodov

  6. #6
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    Re: Dynamic Popup Menus

    Unfortunately, the Thread Tools menu item only pulls down FOUR items...

    There is no "Mark Thread Resolved" item in the pull-down

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Dynamic Popup Menus

    Hmmm, it seems to be a bug in a "new" forum version after the last update
    OK, I'll report it to the Admin.
    Victor Nijegorodov

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