Click here to Skip to main content
12,511,734 members (44,482 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ Windows
I am running the following to create a dialog box in windows. when I run it I get the follwoing error:
Error 1 error C2065: 'IDD_DLGFIRST' : undeclared identifier


Here is the code:


HWND hWnd;
               LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
 
          INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
              LPSTR lpCmdLine, int nCmdShow)
    {
                 DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGFIRST),
                 hWnd, reinterpret_cast<DLGPROC>(DlgProc));
 
              return FALSE;
              }
 
      LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
            {
          switch(Msg)
            {
              case WM_INITDIALOG:
                             return TRUE;
 
                case WM_COMMAND:
              switch(wParam)
            {
              case IDOK:
                      EndDialog(hWndDlg, 0);
                   return TRUE;
            }
               break;
             }
 
              return FALSE;
           }

I do know that there are resource files but I haven't understood that very well. could someone help me out to resolve this error please.
Posted 8-May-13 21:12pm
Comments
p.uday kishore 9-May-13 3:16am
   
check in properties of that dialog whether u have given ID properly or not.
Aayman Khalid 9-May-13 3:37am
   
could you tell me please how do I do that?
p.uday kishore 9-May-13 3:48am
   
r8 click on the dialog and select properties.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You should have declared a dialog in your resource file with the id IDD_DLGFIRST, and you should also have a definition for IDD_DLGFIRST in your resource.h header. Something like:
// project.rc resource file
IDD_DLGFIRST	DIALOGEX	200, 100, 266, 240
STYLE		WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME | DS_CENTER
CAPTION		"Dialog Test"
FONT		10, "Verdana"
BEGIN
	LTEXT			"This is the dialog", IDC_STATIC, 80, 14, 100, 8
END
 
// resource.h header file
#define IDD_DLGFIRST	132
If you are using the Visual Studio dialog and class wizards then these values should be generated automatically for you.
  Permalink  
Comments
CPallini 9-May-13 3:47am
   
5.
Aayman Khalid 9-May-13 5:01am
   
I need a little more of your help,I've performed the steps that you mentioned but I get this: error RC2104 : undefined keyword or key name: WS_POPUP
could you please help me with it?
Richard MacCutchan 9-May-13 7:08am
   
Have you included windows.h in your .rc script file?
Aayman Khalid 9-May-13 7:39am
   
yes.
Richard MacCutchan 9-May-13 7:47am
   
That should include all other necessary headers so WS_POPUP gets defined. Perhaps you can edit your question and add in your dialog definition.
Aayman Khalid 9-May-13 5:04am
   
and if I comment that statement the code does run but the dialog box doesn't appear.instead I get the message that the native has exited with code 0{0x00}
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

These type of symbols are typically defined in a file called resource.h. You can rename the file or use another file but if you haven't done that, it is the place to look first. The resource.h file and app.rc file are maintained by the IDE and can sometimes get out of sync. If this has happened, exit the IDE and edit the resource.h file (eg. notepad or restart the IDE), adding the missing symbol, using a new unique value. Until you understand all the details of resource.h, I suggest a unique value between 1 and 99.
  Permalink  

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 | Mobile
Web02 | 2.8.160929.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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