Click here to Skip to main content
13,869,132 members
Rate this:
Please Sign up or sign in to 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
#include <afxwin.h>
#include "resource.h"
#include "newdialog.h"

class MFC_Tutorial_Window :public CFrameWnd
	CMenu menu1;
        Create(NULL,_T("MFC Tutorial Part 5 CoderSource Dialog"));
    void OnClickDialogNew();
BEGIN_MESSAGE_MAP( MFC_Tutorial_Window, CFrameWnd)
void MFC_Tutorial_Window::OnClickDialogNew()
    newdialog dlg;
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

// newdialog dialog

class newdialog : public CDialog

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

// Dialog Data
    enum { IDD = ID_MYDIALOG };

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


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.
Updated 14-Jun-11 20:28pm
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
AndrewG1231 15-Jun-11 1:24am
Thanks! that worked to resolve the issue with the to work on why the dialog box isn't showing up...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

as written in a comment you need to

#include "resource.h"

in the header, and the ID_MYDIALOG must be defined there

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190214.1 | Last Updated 21 Jun 2011
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100