Re: Command IDs & Dynamic Menus

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Don't forget, you can add (and remove) menu items dynamically. You can also add sub menus dynamically too. This would fit quite nicely with iterating through your xml config file of items. There's no strict requirement to have a menu resource bound into your exe. And if you had one anyway then you can remove all the items then add back the new ones at runtime.

Each item has essentially a text label plus a command ID. These values could be held in the xml file, which would allow your customer to configure what text appear on the item. You're going to need a range of IDs distinct from those that might appear on the rest of the menu or on toolbar buttons, because a command is just a command, regardless of what was pushed to generate it.

Anyway, just a thought.



Nick Meyer wrote:
I'm working on an application that needs to create multiple copies of the same menu dynamically.

The app connects to and monitors the status of several remote systems. Currently, the systems' names and locations are hard-coded. Our company plans to re-use this application for a different customer, who will have a different set of systems to monitor. So, hard coding == bad.

I've updated the app to load the list of systems from an XML file at startup. However, I have a menu in the app that looks like this:

Monitoring
System 1 >
...
System 2 >
...

And so on, where each system has a popup menu underneath the "Monitoring" menu and each of these menus are identical. Clearly, this will have to be created (or loaded and modified) at runtime, based on the contents of the configuration file.

My first thought is to create a resource template for the popup menu that specifies the structure of the popup menu. Then at startup, I'll load this template and append it to the monitoring menu once for each system, using the names given in the file. However, the Command IDs are also specified in the template.

If I use this template multiple times, will I have multiple menu items with the same command ID? How can I work around that? Does anyone have experience designing a feature like this before? Any thoughts about the best way to approach this problem so I can distinguish from which system's popup menu the user selected a particular command?

Thanks,
Nick
.


Quantcast