MFC对话框问题 [英] MFC Dialog Box Question

查看:108
本文介绍了MFC对话框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我将继续完成本教程,并且遇到了另一个未声明的标识符"错误.我检查了resource.h中是否存在定义,但仍然收到错误.同样,这是一个简短的教程,因此代码如下:

So, I am continuing to work through a tutorial and I have run into another ''undeclared identifier'' error. I have checked that the definition exists in resource.h, but I still get the error. Again, it is a short tutorial, so here is the code:

//MFC5.CPP - MFC Tutorial Part 5 from CoderSource.net
#include <afxwin.h>
#include "resource.h"
#include "newdialog.h"

class MFC_Tutorial_Window :public CFrameWnd
{
	CMenu menu1;
public:
    MFC_Tutorial_Window()
    {
        Create(NULL,_T("MFC Tutorial Part 5 CoderSource Dialog"));
		menu1.LoadMenu(IDR_MENU1);
        SetMenu(&menu1);
    }
    void OnClickDialogNew();
    DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP( MFC_Tutorial_Window, CFrameWnd)
    ON_COMMAND(ID_MYDIALOG,OnClickDialogNew)
END_MESSAGE_MAP()
void MFC_Tutorial_Window::OnClickDialogNew()
{
    newdialog dlg;
    dlg.DoModal();
}
class MyApp :public CWinApp



编译器给我以下错误(这是唯一的错误):
newdialog.h(15):错误C2065:``ID_MYDIALOG'':未声明的标识符

错误消息将我带到enum { IDD = ID_MYDIALOG };,它是以下代码的第15行.



The compiler gives me the following error (it is the only error):
newdialog.h(15): error C2065: ''ID_MYDIALOG'' : undeclared identifier

The error message brings me to enum { IDD = ID_MYDIALOG }; which is line 15 from the following code.

<pre lang="cs">#pragma once
#include<afxwin.h>

// newdialog dialog

class newdialog : public CDialog
{
    DECLARE_DYNAMIC(newdialog)

public:
    newdialog(CWnd* pParent = NULL);   // standard constructor
    virtual ~newdialog();

// Dialog Data
    enum { IDD = ID_MYDIALOG };

protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

    DECLARE_MESSAGE_MAP()
};




关于我应该去哪里看有什么建议吗?另外,如果有针对非VC6而为VS2010编写的教程的建议,那将使事情变得更容易.但是,我一直在从错误中学习....

好的,所以我能够通过在newdialog类中包含resource.h(根据建议)来解决编译器问题...但是现在对话框不显示了!我提供了菜单资源,但单击新建"不会导致对话框出现.




Any suggestion on where I should look? Also, if there is a recommendation for a tutorial not written for VC6, but for VS2010 it would make things easier. However, I have been learning by my mistakes....

Ok, so I was able to fix the compiler issue by including resource.h (per advice) in the newdialog class...but now the dialog box doesn''t show! I included a menu resource, but clicking on ''New'' doesn''t cause the dialog box to appear.

推荐答案



#include"resource.h"

在标题中,并且必须在此处定义ID_MYDIALOG
as written in a comment you need to

#include "resource.h"

in the header, and the ID_MYDIALOG must be defined there


这篇关于MFC对话框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆