Date: | August 4, 2005 / year-entry #212 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20050804-10/?p=34713 |
Comments: | 9 |
Summary: | A subtlety that adds a level of polish to your dialogs is supporting double-clicked radio buttons as an abbreviation for "select + OK". (Or "select + Next" or "select + Finish" if the page is part of a wizard.) Consider the following dialog template and associated dialog procedure: 1 DIALOGEX DISCARDABLE 32, 32, 200, 76... |
A subtlety that adds a level of polish to your dialogs is supporting double-clicked radio buttons as an abbreviation for "select + OK". (Or "select + Next" or "select + Finish" if the page is part of a wizard.) Consider the following dialog template and associated dialog procedure: 1 DIALOGEX DISCARDABLE 32, 32, 200, 76 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Sample" FONT 8, "MS Shell Dlg" BEGIN LTEXT "A mumbler is needed.",-1,7,8,100,10 AUTORADIOBUTTON "Do not &obtain a mumber now", 100,17,24,180,10 AUTORADIOBUTTON "Obtain a mumbler auto&matically", 101,17,34,180,10 AUTORADIOBUTTON "&Enter mumbler manually", 102,17,44,180,10 DEFPUSHBUTTON "OK",IDOK,92,58,50,14 PUSHBUTTON "Cancel",IDCANCEL,146,58,50,14 END INT_PTR CALLBACK DlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: CheckRadioButton(hdlg, 100, 102, 100); return TRUE; case WM_COMMAND: switch (GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK: for (int i = 100; i <= 102; i++) { if (IsDlgButtonChecked(hdlg, i)) EndDialog(hdlg, i); } break; case IDCANCEL: EndDialog(hdlg, -1); break; } } return FALSE; } This is pretty standard unexciting dialog box that asks the user to select an option from a list. Notice that double-clicking the radio button doesn't do anything special. We can fix that. 1 DIALOGEX DISCARDABLE 32, 32, 200, 76 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Sample" FONT 8, "MS Shell Dlg" BEGIN LTEXT "A mumbler is needed.",-1,7,8,100,10 AUTORADIOBUTTON "Do not &obtain a mumber now", 100,17,24,180,10,BS_NOTIFY AUTORADIOBUTTON "Obtain a mumbler auto&matically", 101,17,34,180,10,BS_NOTIFY AUTORADIOBUTTON "&Enter mumbler manually", 102,17,44,180,10,BS_NOTIFY DEFPUSHBUTTON "OK",IDOK,92,58,50,14 PUSHBUTTON "Cancel",IDCANCEL,146,58,50,14 END INT_PTR CALLBACK DlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: CheckRadioButton(hdlg, 100, 102, 100); return TRUE; case WM_COMMAND: switch (GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK: for (int i = 100; i <= 102; i++) { if (IsDlgButtonChecked(hdlg, i)) EndDialog(hdlg, i); } break; case IDCANCEL: EndDialog(hdlg, -1); break; case 100: case 101: case 102: if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_DBLCLK) { EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam)); } break; } } return FALSE; }
We added the Note that double-click as a shortcut for select-and-OK should be used only for dialogs or wizard pages where the only relevant controls are radio buttons (and the OK and Cancel buttons). If there are controls on the page other than the radio button, then you have to wait for the OK because the user might want to manipulate those other controls too. This "double-click means select-and-OK" shortcut can also be used if the only thing on the dialog is a list box or list view from with the user is being asked to select one item. If the user double-clicks an item from the list, treat it as select-and-OK. The dialog boxes in Explorer are rather inconsistent in their support for double-clicked radio buttons. The Office and Money teams do a much better job. |
Comments (9)
Comments are closed. |
What are mumbers and mumblers??
8)
A useful technique, but in the specific case of radio buttons I wonder how useful it is. If the only thing I can do in a dialog box is pick an action to be taken then hit okay, well, I’m really not saying what I mean. If I no longer want to Mumblize my Foobar, I click Cancel. If I want one of the other actions, I click the action I want, then OK. What’s the point of confirming (via double-click or OK) at all? It’s hardly a complex dialogue that I might make a mistake on. Instead, wouldn’t it make more sense to have four buttons stacked on top of each other:
[Do not &obtain a mumbler now]
[Obtain a mumbler auto&matically]
[&Enter mumbler manually]
[Don’t mumblize]
It’s down to a single unambiguous click.
The best example of doing this I can think of was WinXP changing the logout radio buttons to normal buttons. I found that a vastly superior solution.
(Oh, and I suspect you meant mumb_l_er in your first radio button.)
I’ve never heard of double-clicking radio buttons before. For the most part I like these nuances in Windows (like holding shift when you active a context menu may reveal additional hidden items). But double-clicking a radio button sounds like it may be more of an annoyance. From time to time I accidently double-click a control. If this happens over a radio button and the dialog closes itself, I would find myself puzzled and annoyed.
That’s funny… I’ve seen wizards where double-clicking a list does a Next as well (add new hardware is one, I think). But I wouldn’t expect double-clicking a button to do anything special because double-clicking a button doesn’t have special significance anywhere; whereas double-clicking a list is special (meaning "do the default action on what I just clicked").
Centaur,
Yeah, they apparently missed this part of the idiom:
Note that double-click as a shortcut for select-and-OK should be used only for dialogs or wizard pages where the only relevant controls are radio buttons (and the OK and Cancel buttons). If there are controls on the page other than the radio button, then you have to wait for the OK because the user might want to manipulate those other controls too.
I have done this before, though since it’s with MFC, it’s only one line of code:
ON_CBN_DBLCLK(IDC_COMBO, OnOK)
ON_LBN_DBLCLK(IDC_LIST, OnOK)
etc.
I have often seen less experienced computer users double-click on *everything* — from buttons to what not. Sometimes I’ve tried to explain what you should single-click and what to double-click, but it actually seems that there isn’t a simple rule for that. At least you should keep that fact in mind when designing new special double-click actions.
Microsoft Visual Studio .NET 7.1 is guilty of misapplying this idiom.
In the Add New Item dialog, there is a vast Templates list view on the right, and a relatively small Name edit below. Now I usually tend to first think *what* it will be, and next *what name* it will have. Occasionally, I double-click the template, at which point the validator complains that "<Enter name>" is not a valid name. Of course it is not; because I was just going to enter it when you interrupted me with your rude modal validation error message box. The double-click here supports the unlikely use case of entering its name first and deciding what it will be next.
Frederik, you’re so right. I laugh inside every time I watch my dad "drive" a computer, he always double-clicks items in the Quick Launch bar to start them. I guess for the non-savvy it’s easier to double-click everything than try and remember which you double-click and which you single click.
GregM said:
> double-click as a shortcut for select-and-OK
> should be used only for dialogs or wizard
> pages where the only relevant controls are
> radio buttons (and the OK and Cancel
> buttons).
Not so. Radio buttons are not the only control that you can click to choose an entry. List & combo boxes are other such controls. The only requirement should be, that there is only one such control on the page.
TC