Click here to Skip to main content
15,037,928 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Ok, so I am new at learning MFC and have been working through a tutorial that has me creating a simple MFC window and adding a menu. I have added the resource and can see the name IDR_MENU1, but I keep getting the message that 'IDR_MENU1' is undefined and an error with ON_COMMAND(). The code looks like this:

#include <afxwin.h>
#include "resource1.h"
class MFC_Tutorial_Window :public CFrameWnd
    CMenu menu1;
        Create(NULL,_T("MFC Tutorial Part 1 CoderSource Window"));
    void OnFileNew();
BEGIN_MESSAGE_MAP( MFC_Tutorial_Window, CFrameWnd)
void MFC_Tutorial_Window::OnFileNew()
    MessageBox(_T("Clicked File->New"));
class MyApp :public CWinApp
    MFC_Tutorial_Window *wnd;
    BOOL InitInstance()
        wnd = new MFC_Tutorial_Window();
        m_pMainWnd = wnd;
        return 1;
MyApp theApp; 

The error I get is:error C2065: 'IDM_FILE_NEW' : undeclared identifier

I feel like I am missing something simple like the resource file not being included in the project...but I can see the .rc file and resource.h in my solution explorer.

I am using in VS2010...(I am also new to posting, so if this should be asked somewhere else I am sorry)

In the Resource View section of Visual Studio, you should see an IDR_MENU1 entry that basically contains that menu (you can see it and add/change entries)... if there's nothing there that says IDR_MENU1, then that's your problem. You may have accidentally changed the name or something similar. Resource.h is the header file that would have the definition of IDM_FILE_NEW, this entry name should also correspond to an entry in the resource viewer by the same name.

Don't change Resource.h or the .rc files directly (outside of the resource view/editor) if you don't know what you're doing.
AndrewG1231 8-Jun-11 23:56pm
So, I checked the Resource View and I see the IDR_MENU1 and resource.h. However, I don't see the IDM_FILE_NEW mentioned in the second solution defined in resource.h. It seems like I forgot to include it in the project somehow.
Albert Holguin 9-Jun-11 0:12am
The lack of that definition is your problem, that's typically added when you add a new entry into your menu resource.... go to your menu and see if it has a "File New" type of entry in it (in resource editor), if its not there, that's your problem, just add it and make sure that the you reference whatever resource ID is given to it (you can change that value)... alternatively, if it is there, make sure that its ID is IDM_FILE_NEW and not something else
In your code you have included
#include "resource1.h"

what is the resource1.h? Like Albert said, the IDM_FILE_NEW will be defined in resource.h. So if you include that file, I guess your problem will be solved.

If you have already included resource.h, check whether IDM_FILE_NEW is defined in that file or not.
AndrewG1231 9-Jun-11 0:00am
I changed it to read resource.h, but I am still getting the errors (red underlines in VS2010 that it is not defined. I see it in my tree (IDR_MENU1) but I cannot find IDM_FILE_NEW. IDR_MENU is also defined in resource.h, but IDM_FILE_NEW is not (I do not see #define IDM_FILE_NEW). I'm not sure, but seems like I am not including it somehow (or defining it).
are you trying to execute some code on clicking file->new menu?
The id of file->New menu by default is 'ID_FILE_NEW' in VC6.
i hope in VS2010 also the same
you might have changed it to 'IDM_FILE_NEW' by mistake by editing in message map.
please check in resource view
The entry ID_FILE_NEW_4007 was in the properties box.

I changed it to IDM_FILE_NEW (as per the tutorial) and compiled. Once resource.h reloaded with the changes it worked!

Thanks for all the help!
Albert Holguin 9-Jun-11 0:50am
good, happy that helped :) ... in the future, post updates by "improving your question" instead of by posting a solution...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900