{"id":6023,"date":"2012-11-22T07:00:00","date_gmt":"2012-11-22T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/11\/22\/the-resource-compiler-will-helpfully-add-window-styles-for-you-but-if-youre-building-a-dialog-template-yourself-you-dont-get-that-help\/"},"modified":"2012-11-22T07:00:00","modified_gmt":"2012-11-22T07:00:00","slug":"the-resource-compiler-will-helpfully-add-window-styles-for-you-but-if-youre-building-a-dialog-template-yourself-you-dont-get-that-help","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20121122-00\/?p=6023","title":{"rendered":"The resource compiler will helpfully add window styles for you, but if you&#039;re building a dialog template yourself, you don&#039;t get that help"},"content":{"rendered":"<p>\nA customer was having trouble with\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/07\/30\/201988.aspx\">\nnested dialogs<\/a>.\nThey were doing something very similar to a property sheet,\nwith a main frame dialog, and then a collection of child dialogs\nthat take turns appearing inside the frame dialog\nbased on what the user is doing.\nThe customer found that if they created the child dialogs with the\n<code>Create&shy;Dialog&shy;Param<\/code> function,\neverything worked great,\nbut if they\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2005\/04\/29\/412577.aspx\">\nbuilt the template at run-time<\/a>,\nkeyboard navigation wasn&#8217;t working right.\nSpecifically, one of their child dialogs contained an edit control,\nand while you could put focus on it with the mouse,\nit was not possible to tab to the control.\nOn the other hand, a resource template didn&#8217;t have this problem.\nTabbing in and out worked just fine.\n<\/p>\n<p>\nThere is logically no difference between a resource-based dialog template\nand a memory-based one,\nbecause\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2005\/03\/29\/403298.aspx\">\nthe resource-based one is implemented in terms of the\nmemory-based one<\/a>.\n<\/p>\n<p>\nThe real problem is the memory-based template you created differs\nsomehow from the one the resource compiler generated.\n<\/p>\n<p>\nOne way to identify this discrepancy is simply to\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/06\/17\/158175.aspx\">\ndo a <code>memcmp<\/code> of the two dialog templates<\/a>,\nthe resource-based one and the memory-based one,\nand see where they differ.\nAfter all, if you want to know why your template doesn&#8217;t match the\none generated by the resource compiler,\nyou can just <i>ask the resource compiler to generate the template<\/i>\nand then compare the two versions.\n<\/p>\n<p>\nInstead of explaining this, I decided to invoke my psychic powers.\n<\/p>\n<blockquote CLASS=\"q\"><p>\nMy psychic powers tell me that you neglected to provide the\n<code>WS_TAB&shy;STOP<\/code> style to the edit control\nwhen you created your in-memory template.\n(You probably didn&#8217;t realize that you needed to do this,\nbecause the resource compile adds that style by default.)\n<\/p><\/blockquote>\n<p>\nWhen you use the resource compiler to generate a dialog template,\nit sets a bunch of styles by default,\ndepending on the type of control.\nFor example,\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa381009(v=VS.85).aspx\">\n<code>EDIT&shy;TEXT<\/code><\/a> says\n&#8220;If you do not specify a style, the default style is\n<code>ES_LEFT | WS_BORDER | WS_TABSTOP<\/code>.&#8221;\n<\/p>\n<p>\nNot mentioned is that the\ndefault style is in addition to the defaults for all\ncontrols:\n<code>WS_CHILD | WS_VISIBLE<\/code>.\n<\/p>\n<p>\nIf you want to turn off one of the default styles for a control,\nyou do so with the <code>NOT<\/code> keyword.\nFor example, if you write\n<\/p>\n<pre>\n   EDITTEXT IDC_AWESOME, 10, 10, 100, 100, ES_MULTILINE | NOT WS_VISIBLE\n<\/pre>\n<p>\nthe resource compiler starts with the default style of\n<\/p>\n<pre>\ndwStyle = WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | WS_TABSTOP;\n<\/pre>\n<p>\nthen it adds <code>ES_MULTI&shy;LINE<\/code>:\n<\/p>\n<pre>\ndwStyle |= ES_MULTILINE;\n\/\/ dwStyle value is now\n\/\/ WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | WS_TABSTOP | ES_MULTILINE\n<\/pre>\n<p>\nand then it removes <code>WS_VISIBLE<\/code>:\n<\/p>\n<pre>\ndwStyle &amp;= ~WS_VISIBLE;\n\/\/ dwStyle value is now\n\/\/ WS_CHILD | ES_LEFT | WS_BORDER | WS_TABSTOP | ES_MULTILINE\n<\/pre>\n<p>\nwhich is the final style applied to the control.\n<\/p>\n<p>\nThe resource compiler is trying to help you out by pre-setting\nthe styles that you probably want,\nbut if you don&#8217;t realize that those defaults are in place,\nyou may not realize that you need to provide them yourself\nwhen you don&#8217;t use the resource compiler.\nMaybe it was being <i>too<\/i> helpful and ended up resulting in\nhelplessness.\n<\/p>\n<p>\nThe customer was kind enough to write back.\n<\/p>\n<blockquote CLASS=\"q\"><p>\nThanks! That did the trick.\n<\/p><\/blockquote>\n<p>\nFor completeness, the default dialog style is\n<code>WS_POPUP&shy;WINDOW =\nWS_POPUP |\nWS_BORDER |\nWS_SYS&shy;MENU<\/code>.\nIf you have a custom font, then you also get\n<code>DS_SET&shy;FONT<\/code>,\nand if you have a caption, then you get\n<code>WS_CAPTION<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer was having trouble with nested dialogs. They were doing something very similar to a property sheet, with a main frame dialog, and then a collection of child dialogs that take turns appearing inside the frame dialog based on what the user is doing. The customer found that if they created the child dialogs [&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-6023","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer was having trouble with nested dialogs. They were doing something very similar to a property sheet, with a main frame dialog, and then a collection of child dialogs that take turns appearing inside the frame dialog based on what the user is doing. The customer found that if they created the child dialogs [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/6023","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=6023"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/6023\/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=6023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=6023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=6023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}