Other tricks with WM_GETDLGCODE

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon