{"id":26263,"date":"2007-06-26T10:00:00","date_gmt":"2007-06-26T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/06\/26\/why-do-dlgc_wantallkeys-and-dlgc_wantmessage-have-the-same-value\/"},"modified":"2007-06-26T10:00:00","modified_gmt":"2007-06-26T10:00:00","slug":"why-do-dlgc_wantallkeys-and-dlgc_wantmessage-have-the-same-value","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20070626-00\/?p=26263","title":{"rendered":"Why do DLGC_WANTALLKEYS and DLGC_WANTMESSAGE have the same value?"},"content":{"rendered":"<p>\nFrom a purely theoretical point of view, there is only one &#8220;want&#8221; code\nyou really need: <code>DLGC_WANTMESSAGE<\/code>.\nAll the others are just conveniences.\nFor example,\nreturning <code>DLGC_WANTARROWS<\/code> means\n&#8220;I want this message if it is an arrow key; otherwise, I don&#8217;t care.&#8221;\nIt lets you write\n<\/p>\n<pre>\ncase WM_GETDLGCODE:\n return DLGC_WANTARROWS;\n<\/pre>\n<p>\ninstead of the more cumbersome (but equivalent)\n<\/p>\n<pre>\ncase WM_GETDLGCODE:\n if (lParam &amp;&amp;\n     ((MSG*)lParam)-&gt;message == WM_KEYDOWN &amp;&amp;\n     (wParam == VK_LEFT || wParam == VK_RIGHT ||\n      wParam == VK_UP || wParam == VK_DOWN)) {\n   return DLGC_WANTMESSAGE;\n }\n return 0;\n<\/pre>\n<p>\nSimilarly, <code>DLGC_WANTTAB<\/code> is equivalent to\nreturning <code>DLGC_WANTMESSAGE<\/code> if the message is a press of the\ntab key,\nand\n<code>DLGC_WANTCHARS<\/code> is equivalent to\nreturning <code>DLGC_WANTMESSAGE<\/code> if the message is <code>WM_CHAR<\/code>.\n<\/p>\n<p>\nAnd that leaves <code>DLGC_WANTALLKEYS<\/code>,\nwhich is just another name for <code>DLGC_WANTMESSAGE<\/code>:\n<\/p>\n<pre>\n#define DLGC_WANTALLKEYS    0x0004\n#define DLGC_WANTMESSAGE    0x0004\n<\/pre>\n<p>\nThey mean the same thing but look at the situation\nthrough different perspectives.\nThe <code>DLGC_WANTMESSAGE<\/code> value is more readable\nif you return it as part of some larger decision-making process,\nlike we did with our mimicry of <code>DLGC_WANTTAB<\/code>:\nYou do a bunch of tests and then when you decide, &#8220;I guess I want\nthis one,&#8221; you return <code>DLGC_WANTMESSAGE<\/code>.\nOn the other hand,\nthe <code>DLGC_WANTALLKEYS<\/code> value is more readable\nif you are just returning it unconditionally.\n&#8220;I want all keys, no matter what it is.&#8221;\n<\/p>\n<p>\nIt&#8217;s like when you&#8217;re at the grocery store,\nand the bagger asks you,\n&#8220;Would you like me to help you carry your watermelon to your car?&#8221;\nYou can say &#8220;Yes&#8221; or &#8220;Always&#8221;; the result is the same.\nThe only difference is one of expectation: If you expect to\nmeet the same bagger in the future, and the bagger remembers,\nthen &#8220;Always&#8221; implies &#8220;You don&#8217;t need to ask me again.&#8221;\nThe dialog manager, on the other hand, doesn&#8217;t have that good of a memory,\nand in fact, if you think about it, you <i>don&#8217;t want it to have a good\nmemory<\/i>.\n<\/p>\n<p>\nSuppose the dialog manager remembered whether you said &#8220;Always&#8221;\nand stopped asking you in the\nfuture.<font FACE=\"Lucida Sans Unicode\">&#x22B6;<\/font>\nIt sends the <code>WM_GETDLGCODE<\/code> message to a control,\nthe control responds <code>DLGC_WANTALLKEYS<\/code>,\nand then later, you subclass the control and change the dialog code.\nOops, that doesn&#8217;t work because the dialog manager &#8220;remembered&#8221;\nthe control&#8217;s previous answer and doesn&#8217;t ask any\nmore.<font FACE=\"Lucida Sans Unicode\">&#x22B7;<\/font>\nNaturally, you expect subclassing to work, so the dialog manager\nasks each time.\n<\/p>\n<p>\nContinuing the analogy, if you want the bagger to help you if it is\nraining but not on a dry day,\nyou can either look out the window, confirm that it is not raining,\nand say, &#8220;Yes&#8221;,\nor you can just say, &#8220;Yes, if it&#8217;s raining,&#8221; regardless of the weather,\nand let the bagger make the call.\n(Of course, the analogy breaks down because the bagger might have a\ndifferent assessment from you as to whether or not it is raining.\nThe decisions you leave up to the dialog manager, such as whether a key\nis the tab key or not, are much less ambiguous.)\n<\/p>\n<p>\nNext time, we&#8217;ll look at a dialog manager problem,\nand the information you learned today may come in handy in solving it.\n<\/p>\n<p>\n<b>Nitpicker&#8217;s corner<\/b>\n<\/p>\n<p>\n<font FACE=\"Lucida Sans Unicode\">&#x22B6;<\/font>Beginning of\ncounterfactual discussion.<font FACE=\"Wingdings\">*<\/font>\n<\/p>\n<p>\n<font FACE=\"Lucida Sans Unicode\">&#x22B7;<\/font>End of\ncounterfactual discussion.<font FACE=\"Wingdings\">*<\/font>\n<\/p>\n<p>\n<font FACE=\"Wingdings\">*<\/font>Warning: Comments complaining about my\nchoice of footnote symbol will be misrepresented and ridiculed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From a purely theoretical point of view, there is only one &#8220;want&#8221; code you really need: DLGC_WANTMESSAGE. All the others are just conveniences. For example, returning DLGC_WANTARROWS means &#8220;I want this message if it is an arrow key; otherwise, I don&#8217;t care.&#8221; It lets you write case WM_GETDLGCODE: return DLGC_WANTARROWS; instead of the more cumbersome [&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-26263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>From a purely theoretical point of view, there is only one &#8220;want&#8221; code you really need: DLGC_WANTMESSAGE. All the others are just conveniences. For example, returning DLGC_WANTARROWS means &#8220;I want this message if it is an arrow key; otherwise, I don&#8217;t care.&#8221; It lets you write case WM_GETDLGCODE: return DLGC_WANTARROWS; instead of the more cumbersome [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/26263","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=26263"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/26263\/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=26263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=26263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=26263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}