# MessageBoxOptions creates opposite results for AlertWindow vs NativeMessageBox

**URL:** <https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899>\
**Category:** General JUCE discussion\
**Created:** [September 7, 2022, 12:33am UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899 "2022-09-07T00:33:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [September 7, 2022, 12:33am UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899/1 "2022-09-07T00:33:08Z")

</div>

On a Mac, building with Juce 6…

Using the same `MessageBoxOptions` object, and going between using `AlertWindow::show` vs `NativeMessageBox::show`, I get opposite button order in the dialog box’s layout. This issue is more than cosmetic – since those methods return an `int` that is “the index of the button that was clicked”, you actually get opposite results for them!

```
    MessageBoxOptions options = MessageBoxOptions()
        .withIconType (MessageBoxIconType::WarningIcon)
        .withTitle ("Here's a question for you...")
        .withMessage ("Will it be Yes/No or No/Yes?")
        .withButton ("Yes")
        .withButton ("No");
    
    int buttonClicked;
    
    buttonClicked = NativeMessageBox::show (options);
    DBG ("the index of the button that was clicked was: " + String (buttonClicked));

    buttonClicked = AlertWindow::show (options);
    DBG ("the index of the button that was clicked was: " + String (buttonClicked));

```

Clicking the **Yes** button in the NativeMessageBox returns a `0`, but clicking the **Yes** button in the AlertWindow returns a `1`.

So, is this an idiosyncrasy of the two formats, or a bug? If it’s a consistent idiosyncrasy, I could program around it… but if it’s a bug that will be fixed, then my workaround would break when it was fixed.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [September 7, 2022, 9:10am UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899/2 "2022-09-07T09:10:18Z")

</div>

This sounds familiar. It’s definitely worth testing with JUCE 7 to see whether the issue has already been fixed.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [September 7, 2022, 5:07pm UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899/3 "2022-09-07T17:07:37Z")

</div>

Yeah, good to check that, but a build with JUCE v7.0.2 produced the same results.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [September 17, 2022, 5:31pm UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899/4 "2022-09-17T17:31:10Z")

</div>

Were you able to verify this on your end?

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [October 28, 2022, 12:42am UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899/5 "2022-10-28T00:42:17Z")

</div>

Circling around to this issue again, here are screenshots produced by the code in my first post, in macOS:

 ![Screen Shot 2022-10-27 at 5.33.21 PM](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/1/1a94685a49a10bba4852f8992133a8b48338de6b.png)  
 ![Screen Shot 2022-10-27 at 5.33.28 PM](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/b/b3e481f3293c72ff4218a4330d757f39fef1f9aa.png)

So, as you can see, for the same `MessageBoxOptions`, JUCE’s alert window is ordering the buttons in reverse order from what the native messages box does. And because both `AlertWindow::show` and `NativeMessageBox::show` return “the index of the button that was clicked”, a “Yes” click returns `1` for the JUCE alert window but a `0` from a native alert window.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [October 28, 2022, 5:13pm UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899/6 "2022-10-28T17:13:30Z")

</div>

Per Apple’s [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/components/presentation/alerts/), the JUCE AlertWindow’s placement of the default button is backwards:

> **Place buttons where people expect.** In general, place the button people are most likely to choose on the trailing side in a row of buttons or at the top in a stack of buttons. Always place the default button on the trailing side of a row or at the top of a stack. Cancel buttons are typically on the leading side of a row or at the bottom of a stack.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [October 29, 2022, 7:03pm UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899/7 "2022-10-29T19:03:04Z")

</div>

Upon further investigation, part of this confusion arises from a conflict of Mac vs Win standards. In Windows, native message boxes are arranged opposite from what Mac does. Here is the same code, generating a NativeMessageBox in Windows:

![Screen Shot 2022-10-28 at 5.31.17 PM](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/c/c3737dfdf0b196e304bd3991b9d6107112905e7e.png)

So the JUCE AlertWindow layout is following the Windows standard, with the affirmative/default option on the left, rather than the Mac standard with it on the right.

---

<div class="post-metadata">

**Author:** ![refusesoftware](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/refusesoftware/32/20561_2.png) [@refusesoftware](https://forum.juce.com/u/refusesoftware)\
**Post date:** [November 1, 2022, 6:12pm UTC](https://forum.juce.com/t/messageboxoptions-creates-opposite-results-for-alertwindow-vs-nativemessagebox/52899/8 "2022-11-01T18:12:51Z")

</div>

@reuk In testing the differences between macOS and Windows displays of NativeMessageBox, I did find what seems to be a bug in Windows.

With this code, [`NativeMessageBox::show`](https://docs.juce.com/master/classNativeMessageBox.html#a23cb367e219442c42eb563ca23e86da4) should return either a `0` for Yes, or a `1` for No. But on Windows, it returns a `2` for No.

```
    MessageBoxOptions options = MessageBoxOptions()
        .withTitle ("Here's a question for you...")
        .withMessage ("Yes or No?")
        .withButton ("Yes")
        .withButton ("No");
    
    int buttonClicked = NativeMessageBox::show (options);
    DBG ("NativeMessageBox::show - index of the button clicked: " + String (buttonClicked));

```
