Why do DLGC_WANTALLKEYS and DLGC_WANTMESSAGE have the same value?


From a purely theoretical point of view, there is only one "want" code you really need: DLGC_WANTMESSAGE. All the others are just conveniences. For example, returning DLGC_WANTARROWS means "I want this message if it is an arrow key; otherwise, I don't care." It lets you write

case WM_GETDLGCODE:
 return DLGC_WANTARROWS;

instead of the more cumbersome (but equivalent)

case WM_GETDLGCODE:
 if (lParam &&
     ((MSG*)lParam)->message == WM_KEYDOWN &&
     (wParam == VK_LEFT || wParam == VK_RIGHT ||
      wParam == VK_UP || wParam == VK_DOWN)) {
   return DLGC_WANTMESSAGE;
 }
 return 0;

Similarly, DLGC_WANTTAB is equivalent to returning DLGC_WANTMESSAGE if the message is a press of the tab key, and DLGC_WANTCHARS is equivalent to returning DLGC_WANTMESSAGE if the message is WM_CHAR.

And that leaves DLGC_WANTALLKEYS, which is just another name for DLGC_WANTMESSAGE:

#define DLGC_WANTALLKEYS    0x0004
#define DLGC_WANTMESSAGE    0x0004

They mean the same thing but look at the situation through different perspectives. The DLGC_WANTMESSAGE value is more readable if you return it as part of some larger decision-making process, like we did with our mimicry of DLGC_WANTTAB: You do a bunch of tests and then when you decide, "I guess I want this one," you return DLGC_WANTMESSAGE. On the other hand, the DLGC_WANTALLKEYS value is more readable if you are just returning it unconditionally. "I want all keys, no matter what it is."

It's like when you're at the grocery store, and the bagger asks you, "Would you like me to help you carry your watermelon to your car?" You can say "Yes" or "Always"; the result is the same. The only difference is one of expectation: If you expect to meet the same bagger in the future, and the bagger remembers, then "Always" implies "You don't need to ask me again." The dialog manager, on the other hand, doesn't have that good of a memory, and in fact, if you think about it, you don't want it to have a good memory.

Suppose the dialog manager remembered whether you said "Always" and stopped asking you in the future. It sends the WM_GETDLGCODE message to a control, the control responds DLGC_WANTALLKEYS, and then later, you subclass the control and change the dialog code. Oops, that doesn't work because the dialog manager "remembered" the control's previous answer and doesn't ask any more. Naturally, you expect subclassing to work, so the dialog manager asks each time.

Continuing the analogy, if you want the bagger to help you if it is raining but not on a dry day, you can either look out the window, confirm that it is not raining, and say, "Yes", or you can just say, "Yes, if it's raining," regardless of the weather, and let the bagger make the call. (Of course, the analogy breaks down because the bagger might have a different assessment from you as to whether or not it is raining. The decisions you leave up to the dialog manager, such as whether a key is the tab key or not, are much less ambiguous.)

Next time, we'll look at a dialog manager problem, and the information you learned today may come in handy in solving it.

Nitpicker's corner

Beginning of counterfactual discussion.*

End of counterfactual discussion.*

*Warning: Comments complaining about my choice of footnote symbol will be misrepresented and ridiculed.

Comments (18)
  1. Anonymous says:

    Shouldn’t the ‘warning’ use a footnote symbol of yellow triangle with an exclamation mark in it? </t-in-c>

  2. Anonymous says:

    These footnotes were brought to you by:

    U+22B6 ORIGINAL OF

    U+22B7 IMAGE OF

    U+002A ASTERISK

  3. Anonymous says:

    "⚠"

  4. JamesNT says:

    @gkdada

    The warning and any other symbols used in this blog are at the discretion of the blog owner.  

    JamesNT

  5. Anonymous says:

    Shouldn’t that be ((MSG*)lParam)->wParam == VK_LEFT || … instead of wParam == VK_LEFT || …

    Ivo

  6. Anonymous says:

    Shouldn’t the footnote symbols be superscripted?

  7. Anonymous says:

    I like your choices of footnote symbols!

    I think every publication, scholarly or otherwise, should use (a) randomly selected symbol(s) on each page.  Of course, the footnote symbol should match the callout or we’ll get (more) confused (than we already are).

    Besides, some of those symbols are under-utilized, and they might get lonely and depressed if they are never allowed out.

  8. :rolleyes:

    <sup>1</sup>

  9. Anonymous says:

    I like your choices of footnote symbols, with one caveat — they should be reversed.

    The filled dot should represent the factual information (ie, fill of info), while the empty dot should be the counterfactual (ie, devoid of facts)

  10. Anonymous says:

    cheech,

    I did not know DLGC_WANTALLKEYS  and DLGC_WANTMESSAGE had the same value.

    even MFC has "DLGC_WANTALLKEYS | DLGC_WANTMESSAGE ".

  11. Anonymous says:

    Some people might like being misrepresented and ridiculed!

  12. Anonymous says:

    While cute, the random footnote symbols (at least this time) don’t automatically stand out as footnotes. I just assumed that my Firefox was misinterpreting some IE-only characters.

  13. Anonymous says:

    Would I be correct to remember some sort of anomaly with cancelling dropdown listboxes, and using DLGC defines?

    All I really remember was having a mare along the lines of those damn defines that MFC toolbars throw at you.

    Ahhhhhh the (ex) joys of LM_MRUWIDTH.

  14. Anonymous says:

    Baggers rarely if ever ask me if I want help carrying out my groceries, so the analogy is invalid.

  15. Anonymous says:

    ScottR: maybe you’re not a) cute enuf; or b) helpless-looking enuf. Also, you’re refutation is invalid because "rarely" does not mean "never". And even if an analogy doesn’t apply to your little universe it doesn’t mean it’s not valid.

  16. Anonymous says:

    what is a bagger? actually I can probably guess… its the poor mexican immigrant getting paid $1/hr to pack groceries into bags for lazy Americans :-)

    Also keep up the footnote fun, it keeps stupid people from writing code since they spend all their time arguing about footnote symbols.

  17. Anonymous says:

    No complaints about footnote symbols here and I don’t even care about them to be honest.

    But this is strange. I am using firefox and I see an asterix just fine. However when used together with the IE tab extension and I visit this place again with an IE view now, the asterix becomes a mail message icon.

  18. Anonymous says:

    Paully: Grocery stores still have to pay Mexican immigrants minimum wage. There were plenty of Mexicans working at the Wendy’s store I worked at before going into IT, and most of them were paid *more* than I was (They had been working at the store longer than I was).

    As for baggers, they’re some random employee that could have been doing anything else. I’ve seen people that worked as cashiers the day before, managers, stockers, anyone will do the bagging. They can be of any gender and any race.

    If you were intending to say *illegal* immagrants, illegals are usually hired to do yard work or construction work. Most major franchise companies won’t hire illegals because it would be a scandal if they were caught. Mom&Pop stores might, though.

    Yes, I lived in southern California where country gas stations doubled as a hard labor recruiting offices (lots of illegals hanging out, looking for work).

    Raymond: Love the footnote symbols.

Comments are closed.