Other tricks with WM_GETDLGCODE

Date:November 26, 2003 / year-entry #142
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20031126-00/?p=41703
Comments:    8
Summary: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...

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. 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. Raymond Chen 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. Use what you know about the WM_GETDLGCODE message

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index