Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable an AfxMessageBox Yes/No (MB_YESNO) "close" button? (upper right corner "X")

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.

like image 863
rec Avatar asked Apr 30 '09 22:04

rec


2 Answers

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

like image 155
i_am_jorf Avatar answered Nov 13 '22 06:11

i_am_jorf


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.

like image 1
Serge Wautier Avatar answered Nov 13 '22 05:11

Serge Wautier