Search code examples
stringmacrosmfcresourcesuint

How to use MFC Resource id stored as string


I am developing an MFC application in which I have menus defined in .rc file. I have an requirement for removing of few menu items at run time which are defined in xml file.

The menu ids are stored as string in xml as like below

<exclusionmenu>ID_FILE_NEW</exclusionmenu>
<exclusionmenu>ID_FILE_OPEN</exclusionmenu>

From xml the menu ids are retrieved as string,

RemoveMenu function expects UINT (menu id),

How to convert the menu id string defined in xml to uint menu id

Note: This is not direct cstring to uint conversion, ID_FILE_NEW is macro and it has int value.


Solution

  • The only way your scenario would work is when you distribute Resoutce.h with your application and you have logic to parse Resource.h at startup into a table containing ID_* names and their values.