Fix message box close behavior
Should fix #4503
Tries to make the message box follow the official behavior described in https://learn.microsoft.com/en-us/dotnet/api/system.windows.messageboxbutton?view=windowsdesktop-10.0#remarks
Particularly regarding the Yes/No type
For that type the close button is to be disabled ( I also hide it), and the close by esc functionality is also disabled
Its not really supposed to have a way to close it without selecting yes or no.
Despite that in the edge case of a forced close (e.g. alt-f4) we still have to decide on a result
It's not 100% clear what the result should be in that case, e.g. Cancel or None
But given how many users of this message box make the mistake of treating !No as Yes, it is probably safer to return No here
Summary by cubic
Aligns MessageBoxEx close behavior with Windows. Hides the close button for Yes/No, fixes titlebar close handling, and sets a safe default result when closed indirectly.
Summary of changes
- Changed
- Hide the close button for Yes/No via named
TitleBar(TitleBar.ShowCloseButton = false). - Disable system caption buttons when using
CustomWindowTitleBar(WindowChrome.UseAeroCaptionButtons = false) so the OS close isn’t clickable behind the custom bar. - Titlebar close now works correctly for supported types and maps to a sensible result; Esc is ignored for Yes/No, and for others falls back to the default result.
- Hide the close button for Yes/No via named
- Added
DefaultCloseResultto mirrorSystem.Windows.MessageBoxwhen closed indirectly: OK→OK, OKCancel/YesNoCancel→Cancel, YesNo→No, else→None.- Initialize
_resulttoDefaultCloseResultbefore showing the dialog to ensure consistent outcomes.
- Removed
- Manual
_resultassignments in Esc/close handlers; rely onDefaultCloseResult.
- Manual
- Memory usage
- No material impact; only a small saved flag and default result state.
- Security risks
- None expected; reduces unintended close paths. Logs a warning if a Yes/No dialog somehow receives a close request.
- Unit tests
- No new tests added.
Release Note
Message boxes now follow Windows behavior: the close button is hidden for Yes/No, and closing the window picks a reasonable default answer.