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. Dynamic menus and messages?

Dynamic menus and messages?

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 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.
  • O Offline
    O Offline
    One Stone
    wrote on last edited by
    #1

    Hello! I am currently trying to make some dynamic menu, i.e. add menu items to the main menu at runtime. For the command IDs, I've registered a ON_COMMAND_RANGE handler in the message map, to intercept different commands from the menu items. Now I wonder: is it better to use the command IDs starting from WM_USER+X or WM_APP+X ??

    A 1 Reply Last reply
    0
    • O One Stone

      Hello! I am currently trying to make some dynamic menu, i.e. add menu items to the main menu at runtime. For the command IDs, I've registered a ON_COMMAND_RANGE handler in the message map, to intercept different commands from the menu items. Now I wonder: is it better to use the command IDs starting from WM_USER+X or WM_APP+X ??

      A Offline
      A Offline
      Antony M Kancidrowski
      wrote on last edited by
      #2

      What I normally do when given such a requirement is to "block off" a set of contiguous command IDs within resource.h that accommodate for the maximum number of elements in the dynamic menu.

      #define ID_DYNAMIC_MENU_START 200
      #define ID_DYNAMIC_MENU_RESERVE1 200
      #define ID_DYNAMIC_MENU_RESERVE2 201
      #define ID_DYNAMIC_MENU_RESERVE3 202
      #define ID_DYNAMIC_MENU_RESERVE4 203
      #define ID_DYNAMIC_MENU_END 203

      Notice I have the DYNAMIC_MENU_START and DYNAMIC_MENU_END pointing at the first and last dynamic menu item respectively. I fill in the ones in the middle as we do not want them used by other resources. We can now set the menu range accordingly. Add to the .h

      afx_msg void OnDynamicMenu(UINT nID);

      Add to the message map

      ON_COMMAND_RANGE(ID_DYNAMIC_MENU_START, ID_DYNAMIC_MENU_END, OnDynamicMenu)

      Add to the .cpp

      void CMyClass::OnDynamicMenu(UINT nID)
      {
      // nID is the ID of the menu clicked
      }

      Ant. I'm hard, yet soft.
      I'm coloured, yet clear.
      I'm fruity and sweet.
      I'm jelly, what am I? Muse on it further, I shall return!
      - David Walliams (Little Britain)

      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