Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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


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()
};



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.
Posted
Updated 14-Jun-11 19:28pm
v2
Comments
Resmi Anna 15-Jun-11 0:07am    
Go to your resource view. check the dialog id of newly created dialog.
Probably it will be something other than 'ID_MYDIALOG'. Pls change it to 'ID_MYDIALOG'.
AndrewG1231 15-Jun-11 0:12am    
The ID and resource match...oddly enough, the problem is not identified in MFC5.cpp but the compiler alerts me when it reaches it in 'newdialog.h' above.
Resmi Anna 15-Jun-11 0:17am    
what is the name of the file that you have given for this dialog class?
also is it needed to include #include<afxwin.h>??
i dont think. you are doing evrything via classwizard rt?
AndrewG1231 15-Jun-11 0:21am    
Yes, the class was added with the class wizard and the class name is 'newdialog'. The afxwin.h is required for CDialog as I understand MSDN.
Resmi Anna 15-Jun-11 0:40am    
#include "resource.h" in your newdialog.h file

1 solution

as written in a comment you need to

#include "resource.h"

in the header, and the ID_MYDIALOG must be defined there
 
Share this answer
 

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