Other tricks with WM_GETDLGCODE


The WM_GETDLCODE message lets you influence the behavior of the dialog manager. A previous entry on using WM_GETDLGCODE described the DLGC_HASSETSEL flag which controls whether edit control content is auto-selected when focus changes.

I was going to write a bit about the other flags, but it turns out that Knowledge Base Article 83302 already covers this, so I'll just call out some highlights.

The DLGC_WANTMESSAGE flag is the most powerful one. It lets your control prevent the dialog manager from handling a message. So for example if you don't want ESC to dismiss the dialog box when focus is on a particular control but rather be delivered to the control itself, handle the WM_GETDLGCODE message and peek at the lParam. If it is a press of the ESC key, then return DLGC_WANTMESSAGE so the message will not be handled by the dialog manager.

The DLGC_WANTCHARS, DLGC_WANTTAB and DLGC_WANTARROWS flags are just conveniences that save you the trouble of checking certain categories of messages.

As always, consider the consequences of overriding default behavior. Doing so generally makes your program harder to use, since it goes against what people are accustomed to seeing in other programs.

Comments (8)
  1. Anonymous says:

    Hey Raymond, can you write an article on how to make the trackbar/scrollbars behave more like sliders. For a certain class of widgets, I don’t like the way the "thumb" pages down instead of going to the exact pixel position when you click on the non-thumb area of a trackbar/scrollbar. Extra bonus points if you can find a way to override that thing in windows to make the thumb jump back to its original position when your mouse cursor is a certain distance away from the scrollbar. Thanks in advance.

  2. Anonymous says:

    "As always, consider the consequences of overriding default behavior. Doing so generally makes your program harder to use, since it goes against what people are accustomed to seeing in other programs."

    :-)

  3. Anonymous says:

    Would you consider changing your feed so that i can get the full text directly in my aggregator… Going to the web site to read you is a pain :)

  4. Anonymous says:

    I use the Description RSS element to provide a short summary of the article. If you are interested in the subject matter, then click through. If not, then scroll past. (I use bloglines and am frustrated by descriptions that go on for pages and pages, making it harder for me to skim. Headlines often aren’t enough to allow me to decide whether an article is worth reading or not; I need a brief summary.)

  5. Anonymous says:

    Use what you know about the WM_GETDLGCODE message

Comments are closed.