views:

1557

answers:

2

When calling:

AfxMessageBox(strMsg, MB_YESNO);

A messagebox with the buttons "Yes" and "No" is displayed. But the "X" (close button) in the upper right corner is disabled, and pressing ESC has no effect.

This is because the only valid results would be IDYES and IDNO, and not IDCANCEL.

Is there a quick way of getting this behavior enabled? What I would like to avoid:

  • Creating a custom dialog for this.
  • Having yes/no/cancel buttons.

In vista, when deleting a file, the dialog asking for confirmation has only "Yes" and "No" and can also be canceled with the close button or with ESC. I'm guessing it's a custom dialog.

+1  A: 

AfxMessageBox() just calls MessageBox() internally. So, no, you can't get the behavior you want here without using MB_YESNOCANCEL which adds a button...

jeffamaphone
A: 

Not sre if does that but Hans Dietrich's free XMessageBox is a very feature-rich extension of the standard message box. You may want yo check it out.

Also, I don't quite understand why you don't want a Cancel button yet want a UI element that does the same but is not quite as explicit.

Edit: Answering your comment:

If 'No' is interchangeable with 'Cancel' then I think 'No' is a bad labelling choice. e.g.: Q asked by a DeleteFolder() function:

"Should I also empty the subfolders?". Obviously, no and Cancel/Escape do not have the same meaning.

OTOH, "Delete files?" looks like the buttons should be Yes/No. But I prefer OK/Cancel. Because you ask for user confirmation, not for more information from user. In such a case, having the Escape key/red cross to work is certainly a plus.

Serge - appTranslator
I think that when the question is "are you sure you want to delete item X" the "cancel" button is redundant because it does the same as clicking "no" button. ESC is for the users that love to use the keyboard. Having the close button "X" enabled just makes sense, because it allows to answer "no" but in a different place in the same dialog. if the buttons "no" and "cancel" are next to each other and they do the same, it doesn't make sense to have both.
rec
Problem is 'no' and 'cancel' are different answers. OK, they may be similar in some cases but it's not guaranteed. Fake example for a "empty folder" function: "Should I also empty the subfolders?", yes/no. Cancels doesn't delete anything. Yes and No do delete some stuff.
Serge - appTranslator