Undeclared Identifier on a Menu Item Entry

Greg Shettlesworth 41 Reputation points
2023-12-28T10:14:15.41+00:00

I've edited the IDR_MAINFRAME menu resource (added a menu item "Simulation" ). The property says the ID for this menu item cannot be edited. OK. I the added a submenu item ("General Parameters") which ID is "ID_SetParameters". So far things are okay. Compiles and executes with no errors, the menu item shows up in the menu, and I can select the "Simulation" menu item and the submenu displays. So far Okay. Now I try to add an event handler for the submenu item "General Parameters" in the document class with the Add Event Handler drop-down option (I also tried the Class Wizard with the same end result) which successfully added code into the CDocument file :

The CRSimDoc.cpp file:

BEGIN_MESSAGE_MAP(CRSimDoc, CDocument)
   ON_UPDATE_COMMAND_UI( ID_SetParameters, &CRSimDoc::OnUpdateSetParameters )
   ON_COMMAND(           ID_SetParameters, &CRSimDoc::OnSetParameters )
END_MESSAGE_MAP()
...
void CRSimDoc::OnUpdateSetParameters( CCmdUI* pCmdUI )
{    // TODO: Add your command update UI handler code here } 

void CRSimDoc::OnSetParameters()
{    // TODO: Add your command handler code here } 

and in the CRSimDoc.h file:
   afx_msg void OnUpdateSetParameters( CCmdUI* pCmdUI );
   afx_msg void OnSetParameters(); 

Compiling generates :
error C2065: 'ID_SetParameters': undeclared identifier
error C2065: 'ID_SetParameters': undeclared identifier

Whats happenning?
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,960 questions
{count} votes

Accepted answer
  1. RLWA32 49,301 Reputation points
    2023-12-28T12:58:46.7766667+00:00

    The menu editor will add the definition of ID_SetParameters to the resource.h header file. This header must be available when the CRSimDoc.cpp file is compiled. One way would be to directly include the header by adding a #include "resource.h" statement in the file or otherwise ensuring that it has been included in a different header file that CRSimDoc.cpp is already referencing.

    1 person found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Greg Shettlesworth 41 Reputation points
    2023-12-28T20:56:57.2733333+00:00

    Thanks - for some reason the resource.h file wasn't being included in the build. All better now, and thanks for the quick response.


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.