在Visual Studio 2010中添加资源 [英] Adding a resource in visual studio 2010
问题描述
好吧,所以我是学习MFC的新手,并且正在研究一个教程,该教程让我创建一个简单的MFC窗口并添加菜单.我已经添加了资源,并且可以看到名称IDR_MENU1,但是我不断收到以下消息:"IDR_MENU1"未定义,并且ON_COMMAND()错误.代码如下所示:
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:
//MFC_Tutorial_5.cpp
#include <afxwin.h>
#include "resource1.h"
class MFC_Tutorial_Window :public CFrameWnd
{
CMenu menu1;
public:
MFC_Tutorial_Window()
{
Create(NULL,_T("MFC Tutorial Part 1 CoderSource Window"));
menu1.LoadMenu(IDR_MENU1);
SetMenu(&menu1);
}
void OnFileNew();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP( MFC_Tutorial_Window, CFrameWnd)
ON_COMMAND(IDM_FILE_NEW,OnFileNew)
END_MESSAGE_MAP()
void MFC_Tutorial_Window::OnFileNew()
{
MessageBox(_T("Clicked File->New"));
}
class MyApp :public CWinApp
{
MFC_Tutorial_Window *wnd;
public:
BOOL InitInstance()
{
wnd = new MFC_Tutorial_Window();
m_pMainWnd = wnd;
m_pMainWnd->ShowWindow(1);
return 1;
}
};
MyApp theApp;
我得到的错误是:error C2065: ''IDM_FILE_NEW'' : undeclared identifier
我感觉好像缺少了一些简单的东西,例如资源文件未包含在项目中...但是我可以在解决方案资源管理器中看到.rc文件和resource.h.
我正在VS2010中使用...(我也是发布的新手,所以如果在其他地方遇到这个问题,我感到抱歉)
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)
推荐答案
在资源视图"部分在Visual Studio中,您应该看到一个IDR_MENU1条目,该条目基本上包含该菜单(您可以看到它并添加/更改条目)...如果那里没有显示IDR_MENU1的条目,那就是您的问题.您可能不小心更改了名称或类似名称. Resource.h是具有IDM_FILE_NEW定义的头文件,该条目名称还应该与资源查看器中的同名条目对应.
如果您不知道自己在做什么,请不要直接更改Resource.h或.rc文件(在资源视图/编辑器外部).
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.
在您的您包含的代码
#include "resource1.h"
什么是资源 1 .h?就像Albert所说的那样,IDM_FILE_NEW将在resource.h中定义.因此,如果您包含该文件,我想您的问题将得到解决.
如果您已经包含resource.h,请检查该文件中是否定义了IDM_FILE_NEW.
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.
您是否要在单击文件->新建菜单时执行一些代码?
在VC6中,文件->新建"菜单的ID默认为"ID_FILE_NEW".
我希望在VS2010中也一样
您可能通过在消息映射中进行编辑而将其错误地更改为"IDM_FILE_NEW".
请在资源视图中查看
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
这篇关于在Visual Studio 2010中添加资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!