在MFC工程中,当我们新建一个源文件并在里面写函数。当函数里面需要用到我们所创建窗体的类的时候,一般我们只需要include该类的头文件,然后在函数里面声明该窗体类的一个对象即可,然后往往会出现这样的编译错误提示:error C2065: 'IDD_DIALOG1' : undeclared identifier (注:IDD_DIALOG1是我所创建窗体的id号)。出现这个原因是没有定义(废话,呵呵),我们知道资源的定义都是在resources.h文件中,所以解决方法也就容易知道:只要include这个资源头文件即可;另外由于工程主文件的头文件中也是包含这个资源文件的,所以另外一种方法是包含这个工程的头文件即可。
摘自网上的一个解决方法:
Usually this happens in the following scenario: you create a new dialog class, with 2 files, let's say MyDialog.h and MyDialog.cpp. In the .cpp file you have only the following includes:
#include "stdafx.h"
#include "MyDialog.h"
By the time you include MyDialog.h, your IDD_DIALOG1 defined in resource.h is not know. You must include that header. So you have several options:
you include the resource file definition in your MyDialog.h
you include the header for your CWinApp derived class, in your source file, before including MyDialog.h
#include "stdafx.h"
#include "MyWinApp.h" // this file includes resource.h
#include "MyDialog.h"
PS: notice this is a very old thread