{"id":28123,"date":"2007-02-06T10:00:05","date_gmt":"2007-02-06T10:00:05","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/02\/06\/why-cant-i-create-my-dialog-box-rookie-mistake-1\/"},"modified":"2007-02-06T10:00:05","modified_gmt":"2007-02-06T10:00:05","slug":"why-cant-i-create-my-dialog-box-rookie-mistake-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20070206-05\/?p=28123","title":{"rendered":"Why can&#039;t I create my dialog box? Rookie mistake #1"},"content":{"rendered":"<p>\nEach dialog box resource is specified either by an integer ordinal\nor by a string name.\nBut a simple typo will turn one into the other.\n<\/p>\n<pre>\n#define DLG_OPEN 1\n#define DLG_WARN_REMOVEABLE 2\nDLG_OPEN DIALOG 32, 32, 267, 73\n...\nBEGIN\n  ...\nEND\nDLG_WARN_REMOVABLE DIALOG 32, 32, 267, 73\n...\nBEGIN\n  ...\nEND\nDialogBox(hInstance, TEXT(\"DLG_OPEN\"),\n          hwnd, OpenDialogProc);\nDialogBox(hInstance, MAKEINTRESOURCE(DLG_WARN_REMOVEABLE),\n          hwnd, WarnRemoveableDialogProc);\n<\/pre>\n<p>\nDo you see the two &#8220;classic rookie mistakes&#8221;?\n<\/p>\n<p>\nIt may be easier to spot if you take the resource file and\nsend it through the preprocessor first:\n<\/p>\n<pre>\n1 DIALOG 32, 32, 267, 73\n...\nBEGIN\n  ...\nEND\nDLG_WARN_REMOVABLE DIALOG 32, 32, 267, 73\n...\nBEGIN\n  ...\nEND\n<\/pre>\n<p>\nThe first call to <code>DialogBox<\/code> passes\n<code>TEXT(\"DLG_OPEN\")<\/code> as the resource name.\nBut notice that there is no resource with that name.\nThe preprocessor turned <code>DLG_OPEN<\/code> into <code>1<\/code>\nthanks to the line <code>#define DLG_OPEN 1<\/code> in the header file.\nTherefore, the call to <code>DialogBox<\/code> fails\nsince there is no dialog box named <code>DLG_OPEN<\/code>.\nThe dialog box you want goes by the integer name&nbsp;1.\n<\/p>\n<pre>\nDialogBox(hInstance, MAKEINTRESOURCE(DLG_OPEN),\n          hwnd, OpenDialogProc);\n<\/pre>\n<p>\nThe second mistake is more subtle.\nNotice that the name of the second dialog is spelled inconsistently.\nThe header file calls it <code>DLG_WARN_REMOVEABLE<\/code>, but the\nresource file calls it <code>DLG_WARN_REMOVABLE<\/code>.\nAs a result, the preprocessor macro is <strong>not<\/strong> invoked,\nand the result is a dialog that goes by the string name\n<code>TEXT(\"DLG_WARN_REMOVABLE\")<\/code>.\nHowever, the code asks for\n<code>MAKEINTRESOURCE(DLG_WARN_REMOVEABLE)<\/code>,\nwhich doesn&#8217;t exist.\n<\/p>\n<p>\nTo fix the second issue, you first have to decide what you really wanted.\nYou probably wanted an integer dialog resource,\nin which case the fix is to correct the resource file:\n<\/p>\n<pre>\nDLG_WARN_REMOVEABLE DIALOG 32, 32, 267, 73\n<\/pre>\n<p>\nOn the other hand, if you really wanted the dialog box to be\na named resource (note: this is extremely rare), then you need\nto request it by name:\n<\/p>\n<pre>\nDialogBox(hInstance, TEXT(\"DLG_WARN_REMOVABLE\"),\n          hwnd, WarnRemoveableDialogProc);\n<\/pre>\n<p>\nWe&#8217;ll look at a few more &#8220;rookie mistakes&#8221; over the next couple of days.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Each dialog box resource is specified either by an integer ordinal or by a string name. But a simple typo will turn one into the other. #define DLG_OPEN 1 #define DLG_WARN_REMOVEABLE 2 DLG_OPEN DIALOG 32, 32, 267, 73 &#8230; BEGIN &#8230; END DLG_WARN_REMOVABLE DIALOG 32, 32, 267, 73 &#8230; BEGIN &#8230; END DialogBox(hInstance, TEXT(&#8220;DLG_OPEN&#8221;), hwnd, [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-28123","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Each dialog box resource is specified either by an integer ordinal or by a string name. But a simple typo will turn one into the other. #define DLG_OPEN 1 #define DLG_WARN_REMOVEABLE 2 DLG_OPEN DIALOG 32, 32, 267, 73 &#8230; BEGIN &#8230; END DLG_WARN_REMOVABLE DIALOG 32, 32, 267, 73 &#8230; BEGIN &#8230; END DialogBox(hInstance, TEXT(&#8220;DLG_OPEN&#8221;), hwnd, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/28123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=28123"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/28123\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=28123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=28123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=28123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}