Last updated:
22. July 2001
(Start sub-menu)
User Interface Programming Column
Splitter Controls and Dialog Resizing
(End sub-menu)
I’d like to draw your attention to a user interface bug that runs rampant through the world of Windows applications. It involves the interaction of multiline edit controls and default pushbuttons.
Early versions of Windows came equipped with the multiline edit control. Entering multiple lines was cumbersome, as it required you to press Ctrl+Enter instead of just Enter. This was especially unfortunate when a default pushbutton was also operative: users would hit Enter to start a new line and promptly lose the whole dialog box (along with their peace of mind). This Ctrl+Enter business was so obscure that many applications added extra text to educate users in proper procedure, e.g., “Hit Ctrl+Enter for new line.” Mistakes were nevertheless common, even among experienced users.
This is the best Windows 3.1 link I’ve been able to find on Microsoft’s site.
Poor little orphan…
Along came Windows 3.1 and the ES_WANTRETURN style, and all was well with the world. Or was it? The problem was now turned on its head; users would type some text and then press Enter to invoke the default pushbutton. What they got was a new line (along with a fresh set of aggravations). The old style of interaction was merely bad. The new style, when used in the wrong context, was an actual bug in the user interface. That bug has been with us ever since.
There are three approaches to fixing the problem:
The first solution is beyond the current state of the art. The second solution is easy; just remove the ES_WANTRETURN style from the edit controls. Unfortunately, this results in a bad user interface. The third solution is the only sensible way to handle the problem. Some applications use it, others don’t. Still others are inconsistent; this last group even includes luminaries such as WinWord 97.
In fact, I did develop a general solution two years later; see the Default Button Handling article.
“General” turned out to be better after all.
There are two possibilities: either create a general and reusable solution, or handle it on a case-by-case basis. If the goal is to keep total complexity at a minimum, I think most projects will benefit from a case-by-case handling. What little code is involved is very straightforward, and probably easier to understand than any interface to a general solution would be. (Though if you already have a common dialog base class in your project, you might consider a general solution.)
Figure 1 shows a code fragment that illustrates how one might go about implementing this in a simple fashion. The example uses MFC; non-MFC code should handle the EN_SETFOCUS and EN_KILLFOCUS notifications from the multiline edit controls. These notifications are delivered through the WM_COMMAND message.
A final caveat: The Visual Studio documentation includes an article entitled “Dialog Box Keyboard Interface.” I advise you to read this carefully before you start tampering with default buttons in your own code. If you only read the documentation on DM_SETDEFID, you’ll be left with the inaccurate impression that this is a straightforward business. For example, do you really need to both set the dialog’s default ID and change the style of the button? Yes, you do. The interaction between dialogs, default buttons and the keyboard is a complex and not terribly well-designed business.
(Start bottom menu)
Top •
Home
• Articles
• Book
• Resources
Windows Developer Magazine
• R&D Books
• CMP Books
Amazon.com
• Amazon.co.uk
• Contact Petter Hesselberg
(End bottom menu)