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.
Undeclared Identifier on a Menu Item Entry
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++
3 additional answers
Sort by: Most helpful
-
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.
-
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
-
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