6

I read in Windows Experience Guidelines: Error Messages that "OK" is an incorrect button to display on an error dialog.

...provide a Close button. Don't use OK for error messages, because this wording implies that problems are OK.

So, how can I display a simple error dialog with a single Close/Cancel button?

Is this possible with the standard MessageBox class or must I resort to custom dialog (or library) or other Win32 message / p-invoke "hacks"?

(There doesn't seem to be anything relevant in the MessageBoxButtons enumeration.)

Thanks.

  • If there's nothing in the `MessageBoxButtons` enum, this might be because you don't really need anything else. I clearly understand your point about an [OK] button, but it all depends on the ind of problem you've encountered. What else you want the user to anwer? He doesn't agree and wanna do something about this error? I don't think so. In my point of view, I would simply use the standard `MessageBox`, otherwise you'll have to implement your own, which shouldn't be too difficult. – Will Marcouiller Jan 28 '12 at 00:18
  • @WillMarcouiller But one *does* need something else, according to the *official* Microsoft design documentation linked :-) I believe it is targeted to Vista/Windows7, but the question still stands as MessageBox (and the underlying [MessageBox WinAPI](http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx)) does not provide this option: which simply means they not been "updated for the times". (And has nothing to do with "you don't really need anything else".) –  Jan 28 '12 at 00:29

1 Answers1

7

You want the all-improved TaskDialog.

Available from here with description on usage here

TaskDialog allows you to specify in more detail the buttons and icons that show and is microsoft's own solution to your problem in .Net.

-- update to answer @pst's comment

If you have to support Winows XP or earlier then there is a very stable and reliable library on codeproject which wraps and emulates the microsoft taskdialog class when you are using an earlier version of windows, and uses MS's own version if you are on Vista or later.

I have relied on this codeproject library approx 2 years ago, and it was stable then, so there should be no reliability issues at all.

perfectionist
  • 4,256
  • 1
  • 23
  • 34
  • Nice find. I wonder what would happen if running on Windows XP, though? (It makes it sounds like it uses a Vista/Windows7-only API.) –  Jan 28 '12 at 00:32
  • Then it is automatically going to be cancelled :) – Hans Passant Jan 28 '12 at 00:43
  • Thanks for your input (and update). I did not even realize Vista/7 introduced a new TaskDialog API. Do you know of, of had experience with, issues (or performance concerns) when using these WPF dialogs in a WinForms application/host? –  Jan 28 '12 at 21:52
  • 1
    I've experienced no problems at all. The TaskDialog class is pretty neat, allowing you to (for example) use a custom icon, custom buttons, or even more interesting stuff like radio buttons. It all hangs together smoothly. The only gotcha I ever noticed was that if you choose one of the default icons, it assumed you wanted some other behaviour - i think it was a default sound - (so choosing an error icon might play the windows default error noise) - but you could work around this by providing your own custom icon (which might look identical). – perfectionist Jan 28 '12 at 22:45