Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Dynamc Pop-up Menu?

Dynamc Pop-up Menu?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Josh Knox
    wrote on last edited by
    #1

    Hi, I need to put together a context menu within an app that can display options that aren't known at compile time. I can create a normal pop-up menu alright I just don't know where to look to populate the menu with items that are, for instance, defined in a user configurable file. Any Ideas??? Josh Knox

    We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin

    ---Bob3D---

    P 1 Reply Last reply
    0
    • J Josh Knox

      Hi, I need to put together a context menu within an app that can display options that aren't known at compile time. I can create a normal pop-up menu alright I just don't know where to look to populate the menu with items that are, for instance, defined in a user configurable file. Any Ideas??? Josh Knox

      We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin

      ---Bob3D---

      P Offline
      P Offline
      Pavel Klocek
      wrote on last edited by
      #2

      If you are using MFC, you can use CMenu methods like AppendMenu. Following code snippet loads menu from resources and adds a separator and a dynamic menuitem:

      void CMyView::OnContextMenu(CWnd* pWnd, CPoint point)
      {
      {
      if (point.x == -1 && point.y == -1){
      //keystroke invocation
      CRect rect;
      GetClientRect(rect);
      ClientToScreen(rect);

      		point = rect.TopLeft();
      		point.Offset(5, 5);
      	}
      
      	CMenu menu;
      	//You can optionaly load a static part of the menu from resources
                  VERIFY(menu.LoadMenu(IDR\_CONTEXT\_MENU));
      
      	CMenu\* pPopup = menu.GetSubMenu(0);
      	ASSERT(pPopup != NULL);
      
      	pPopup->AppendMenu(MF\_SEPARATOR);
      	pPopup->AppendMenu(MF\_STRING,1111,"Dynamic");
      
      	CWnd\* pWndPopupOwner = this;
      
      	while (pWndPopupOwner->GetStyle() & WS\_CHILD)
      		pWndPopupOwner = pWndPopupOwner->GetParent();
      
      	pPopup->TrackPopupMenu(TPM\_LEFTALIGN | TPM\_RIGHTBUTTON, point.x, point.y,
      		pWndPopupOwner);
      }
      

      }

      If you want the menu completely dynamic, then add a MF_POPUP instead of LoadMenu. Pavel Sonork 100.15206

      J 1 Reply Last reply
      0
      • P Pavel Klocek

        If you are using MFC, you can use CMenu methods like AppendMenu. Following code snippet loads menu from resources and adds a separator and a dynamic menuitem:

        void CMyView::OnContextMenu(CWnd* pWnd, CPoint point)
        {
        {
        if (point.x == -1 && point.y == -1){
        //keystroke invocation
        CRect rect;
        GetClientRect(rect);
        ClientToScreen(rect);

        		point = rect.TopLeft();
        		point.Offset(5, 5);
        	}
        
        	CMenu menu;
        	//You can optionaly load a static part of the menu from resources
                    VERIFY(menu.LoadMenu(IDR\_CONTEXT\_MENU));
        
        	CMenu\* pPopup = menu.GetSubMenu(0);
        	ASSERT(pPopup != NULL);
        
        	pPopup->AppendMenu(MF\_SEPARATOR);
        	pPopup->AppendMenu(MF\_STRING,1111,"Dynamic");
        
        	CWnd\* pWndPopupOwner = this;
        
        	while (pWndPopupOwner->GetStyle() & WS\_CHILD)
        		pWndPopupOwner = pWndPopupOwner->GetParent();
        
        	pPopup->TrackPopupMenu(TPM\_LEFTALIGN | TPM\_RIGHTBUTTON, point.x, point.y,
        		pWndPopupOwner);
        }
        

        }

        If you want the menu completely dynamic, then add a MF_POPUP instead of LoadMenu. Pavel Sonork 100.15206

        J Offline
        J Offline
        Josh Knox
        wrote on last edited by
        #3

        Thanks Pavel, That'll work great. My next question is how to map commands to the dynamically added menu items? Josh Knox

        We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin

        ---Bob3D---

        A P 2 Replies Last reply
        0
        • J Josh Knox

          Thanks Pavel, That'll work great. My next question is how to map commands to the dynamically added menu items? Josh Knox

          We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin

          ---Bob3D---

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Sorry I can't help you, but I had the same problem. I dynamically create a menu that contain a certain number of IP adresses, like : _TRAYMENU_ 192.168.0.1 62.43.12.10 etc... and I want to copy the IP to the clipboard when I click on it (I know for the clipborad, but I don't know how to map commands...) Thanks!

          J 1 Reply Last reply
          0
          • A Anonymous

            Sorry I can't help you, but I had the same problem. I dynamically create a menu that contain a certain number of IP adresses, like : _TRAYMENU_ 192.168.0.1 62.43.12.10 etc... and I want to copy the IP to the clipboard when I click on it (I know for the clipborad, but I don't know how to map commands...) Thanks!

            J Offline
            J Offline
            Josh Knox
            wrote on last edited by
            #5

            Look up the DYNAMENU sample in MSDN. It details how to do this stuff. Josh Knox

            We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin

            ---Bob3D---

            1 Reply Last reply
            0
            • J Josh Knox

              Thanks Pavel, That'll work great. My next question is how to map commands to the dynamically added menu items? Josh Knox

              We will rid the world of buttmunching pussnuts. Armed only with my blunt spoon of death and my circumcising potato peeler. Death and torture to them all. - Michael Martin

              ---Bob3D---

              P Offline
              P Offline
              Pavel Klocek
              wrote on last edited by
              #6

              Add an ON_COMMAND or ON_COMMAND_RANGE macros to the message map section of the class where you want to catch them:

              BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
              //{{AFX_MSG_MAP(CMainFrame)
              ON_WM_CREATE()
              ON_COMMAND(ID_VIEW_DLLTEST, OnViewDlltest)
              ... and other macros added by class wizard
              //}}AFX_MSG_MAP
              ON_COMMAND(ID_xxxx, OnXxxx) //<<< manually add the handler mapping here
              END_MESSAGE_MAP()

              You also need to add the void OnXxxx() method to your class. Pavel Sonork 100.15206

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups