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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Dynamically-built Menus

Dynamically-built Menus

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 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.
  • S Offline
    S Offline
    Sean Payne
    wrote on last edited by
    #1

    Hello all! I'm an intermediate programmer, and need help on this particular issue: I have a program that runs with plugins that are loaded at run-time. Plug-ins can be installed and deleted and the program runs without a hitch. But I've been having a problem trying to come with some method of allowing the addition of menu items to a tray icon's menu at run-time and handling when the user clicks on these menu items. I've seen something similar done, where a basic menu is created then the program adds items at run-time and handles them as well, but the ID Routing is something that I'm having trouble with. Does anybody have any suggestions, or even source code with this type of feature? Thanks for all your help! Sean Payne (Zero_Divide_1)

    R 1 Reply Last reply
    0
    • S Sean Payne

      Hello all! I'm an intermediate programmer, and need help on this particular issue: I have a program that runs with plugins that are loaded at run-time. Plug-ins can be installed and deleted and the program runs without a hitch. But I've been having a problem trying to come with some method of allowing the addition of menu items to a tray icon's menu at run-time and handling when the user clicks on these menu items. I've seen something similar done, where a basic menu is created then the program adds items at run-time and handles them as well, but the ID Routing is something that I'm having trouble with. Does anybody have any suggestions, or even source code with this type of feature? Thanks for all your help! Sean Payne (Zero_Divide_1)

      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      If you use TrackPopupMenu to display it, use the TPM_RETURNCMD flag so that the selected option code is returned locally to the procedure that calls TrackPopupMenu() (i.e. not a WM_COMMAND message sent to you). If its one you recognise, you porcess it locally, else you have to check each of your plug-ins to see if they are the one to handle it. Similary, your plug-ins will have a procedure to setup the dynamic menu, something like this: CMenu menu; menu.CreatePopupMenu(); // or use LoadMenu and GetSubMenu(0) menu.AppendMenu(...) ; // add local commands for each plug-in { plugin.AddMenuItems(menu); } int sel = TrackPopupMenu(menu, TPM_RETURNCMD, ...) switch (sel) { case 0: // aborted break; case MY_COMMAND1: ... case MY_COMMANDX: break; default: // command added by plug-in, check the plugins to see who needs to handle it } A quick pseudo code hack above, but should give you the idea. Roger Allen - Sonork 100.10016 If your dead and reading this, then you have no life!

      Z 1 Reply Last reply
      0
      • R Roger Allen

        If you use TrackPopupMenu to display it, use the TPM_RETURNCMD flag so that the selected option code is returned locally to the procedure that calls TrackPopupMenu() (i.e. not a WM_COMMAND message sent to you). If its one you recognise, you porcess it locally, else you have to check each of your plug-ins to see if they are the one to handle it. Similary, your plug-ins will have a procedure to setup the dynamic menu, something like this: CMenu menu; menu.CreatePopupMenu(); // or use LoadMenu and GetSubMenu(0) menu.AppendMenu(...) ; // add local commands for each plug-in { plugin.AddMenuItems(menu); } int sel = TrackPopupMenu(menu, TPM_RETURNCMD, ...) switch (sel) { case 0: // aborted break; case MY_COMMAND1: ... case MY_COMMANDX: break; default: // command added by plug-in, check the plugins to see who needs to handle it } A quick pseudo code hack above, but should give you the idea. Roger Allen - Sonork 100.10016 If your dead and reading this, then you have no life!

        Z Offline
        Z Offline
        Zero_divide_1
        wrote on last edited by
        #3

        Hey, thanks a lot! That idea is so much better than the one I came up with. In fact, 2 hours ago I finished a class to handle the requests using ON_COMMAND_RANGE and having the class lookup the correct callback function in the plug-in to call, but your idea is so much better. Maybe I should write an article and post it on CodeProject to help all those other coders out there who need help with this type of problem as well (don't worry, I'll mention that you told me about this possibility - I don't like taking credit for things that I didn't come up with). Thanks so much! Sean Payne (Zero_Divide_1)

        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