Click here to Skip to main content
14,641,269 members
Rate this:
Please Sign up or sign in to vote.
See more:
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)
              case WM_INITDIALOG:
                             return TRUE;

                case WM_COMMAND:
              case IDOK:
                      EndDialog(hWndDlg, 0);
                   return TRUE;

              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.
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:
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
CAPTION		"Dialog Test"
FONT		10, "Verdana"
	LTEXT			"This is the dialog", IDC_STATIC, 80, 14, 100, 8

// 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.
CPallini 9-May-13 3:47am
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
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:
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.

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

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