Click here to Skip to main content
13,708,005 members

MFC Dialog Box Question

AndrewG1231 asked:

Open original thread
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.
Tags: C++, Visual-Studio (VS2010), MFC

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180920.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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