2

In the software I maintain I plan to replace the old MessageBox by TaskDialog as suggested by Microsoft UI guidlines already quite some time ago.

The main issue I need to resolve is following:

The old message box invoked via MessageBox(... ,MB_OK) (thus containing only an OK button) can be dismissed by pressing the Esc key.

But a TaskDialog containing only an OK button cannot be dismissed by pressing Esc. This might have a negative impact on the user experience.

I tried to use TaskDialogIndirect using the pfCallback field, but if the there is no Cancel button in the task dialog, the callback function doesn't even get called.

Any ideas what can be done so Esc will dismiss such a task dialog?

Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • 1
    This kinda makes sense. If the dialog has no cancel button, then why should ESC have any effect. Isn't the solution to add a cancel button? – David Heffernan Jun 26 '19 at 16:01
  • @DavidHeffernan yes that actually works!! If there is only a Cancel button in the task dialog, then Esc __and__ Enter dismiss the dialog which is exactly what I want. The only thing I need to do is label the cancel button "OK" instead of "Cancel" which is easy with `TaskDialogIndirect`. You saved my day. – Jabberwocky Jun 26 '19 at 16:07
  • That sounds like a terrible idea. Cancel implies that you are backing out of an action and undoing / not performing it. ESC invokes cancel. ESC should not invoke a button marked OK. Perhaps this is your opportunity to correct the UX in your app's dialogs. – David Heffernan Jun 26 '19 at 16:08
  • @DavidHeffernan I think you misunderstood by comment. If I label the `IDCANCEL` buttton with the text "OK", then the user just sees a kind of message box with one OK button. Then he just presses Esc or Enter (like with the old MessageBox) and the dialog is dismissed. I would use this hack only if there is a single OK button in the task dialog. As I mentioned before, the old `MessageBox` containing a single OK button can be dismissed with Enter and with Esc. – Jabberwocky Jun 26 '19 at 16:13
  • I don't think I misunderstood. I think that a message box with an OK button should not be cancelled with ESC (cancel). Instead it should take an ENTER (accept) to dismiss it. So I would regard the classic `MessageBox` as being flawed. – David Heffernan Jun 26 '19 at 16:19
  • Your're right, but that's what 1000s of users are used to. – Jabberwocky Jun 26 '19 at 16:28
  • In your program perhaps, but not in other programs, and they'll soon get used to the change. My app has been through the same change when we adopted task dialog and none of my users said anything. – David Heffernan Jun 26 '19 at 16:41
  • 1
    No, 1000s of users are not used to a task dialog closing when it displays an OK button and they hit Esc. If it worked that way, you wouldn't be needing to ask this question about how to break the designed behavior of the dialog. – Ken White Jun 26 '19 at 17:30
  • @KenWhite you are right, they are not used to close a task dialog with Esc, but they are used to close the old MessageBox (which I want to replace by a task dialog) with Esc. – Jabberwocky Jun 26 '19 at 18:07
  • Have you considered using MessageBox? – David Heffernan Jun 26 '19 at 18:58
  • @DavidHeffernan I am using MessageBox right, now, but I want to get rid of it. Anyway I found a suitable solution. – Jabberwocky Jun 26 '19 at 19:00
  • Sounds like a non problem. You want something that behaves exactly as MessageBox does. That thing is MessageBox! – David Heffernan Jun 26 '19 at 19:02
  • @DavidHeffernan I want the behavoir of the ugly message box but the nice look of the task dialog. But as I said, I found a suitable solution. But you are right, MessageBox with only an OK button should not be dismissable by Esc, but it has been like that since Windows 3 – Jabberwocky Jun 26 '19 at 19:06

1 Answers1

5

The MSDN documentation for the TASKDIALOGCONFIG structure says the following about the TDF_ALLOW_DIALOG_CANCELLATION flag (the dwFlags member):

Indicates that the dialog should be able to be closed using Alt-F4, Escape, and the title bar's close button even if no cancel button is specified in either the dwCommonButtons or pButtons members.

This flag also gives the dialog box a system menu (Alt+Space), so you can also close it by pressing Alt+Space and the underlined character in the system menu's "Close" item.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384