在Windows中创建对话框 [英] Dialog Box creation in windows

查看:303
本文介绍了在Windows中创建对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下命令在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.

推荐答案

你应该在资源文件中声明一个id IDD_DLGFIRST ,您还应该在resource.h标头中定义 IDD_DLGFIRST 。类似于:

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



如果您使用的是Visual Studio对话框和类向导,那么这些值应该是为您自动生成。


If you are using the Visual Studio dialog and class wizards then these values should be generated automatically for you.


这些类型的符号通常在名为resource.h的文件中定义。您可以重命名该文件或使用其他文件,但如果您没有这样做,则首先要查看该文件。 resource.h文件和app.rc文件由IDE维护,有时可能不同步。如果发生这种情况,请退出IDE并编辑resource.h文件(例如记事本或重新启动IDE),使用新的唯一值添加缺少的符号。在你了解resource.h的所有细节之前,我建议一个介于1和99之间的唯一值。
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.


这篇关于在Windows中创建对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆