Skip to content

[API Proposal]: Make Help button available in MessageBox #9619

Open
@bstordrup

Description

@bstordrup

Background and motivation

Split from the API Proposal in #9613.

The MessageBox API in Windows has an ability to make a Help button available in the UI. This involves the MB_HELP value in the style for the MessageBox call.

Doing so, developers will be able to integrate help into messages being shown making the end users able to read more information about a message.

API Proposal

The proposal is to add help related parameters to MessageBox.Show method in the same way as in WinForms repository.

It would be something like this:

namespace System.Windows 
{
    class MessageBox
    {
        public static MessageBoxResult Show(
            string messageBoxText,
            string caption,
            MessageBoxButton button,
            MessageBoxImage icon, 
            MessageBoxResult defaultResult,
            MessageBoxOptions options,
+           bool displayHelpButton);

        public static MessageBoxResult Show(
            string messageBoxText,
            string caption,
            MessageBoxButton button,
            MessageBoxImage icon, 
            MessageBoxResult defaultResult,
            MessageBoxOptions options,
+           string helpFilePath);

        public static MessageBoxResult Show(
            Window owner,
            string messageBoxText,
            string caption,
            MessageBoxButton button,
            MessageBoxImage icon, 
            MessageBoxResult defaultResult,
            MessageBoxOptions options,
+           string helpFilePath);

        public static MessageBoxResult Show(
            string messageBoxText,
            string caption,
            MessageBoxButton button,
            MessageBoxImage icon, 
            MessageBoxResult defaultResult,
            MessageBoxOptions options,
+           string helpFilePath,
+           string keyWord);

        public static MessageBoxResult Show(
            Window owner,
            string messageBoxText,
            string caption,
            MessageBoxButton button,
            MessageBoxImage icon, 
            MessageBoxResult defaultResult,
            MessageBoxOptions options,
+           string helpFilePath,
+           string keyWord);
        
    }
}

The implementation in WinForms repository will be a source of inspiration for implementing this.

Also, the underlying Windows API has a value for a default button 4. It can be made available also like this:

namespace System.Windows
{
    public sealed class MessageBox
    {
        private const int DEFAULT_BUTTON1 = 0x00000000;
        private const int DEFAULT_BUTTON2 = 0x00000100;
        private const int DEFAULT_BUTTON3 = 0x00000200;
+       private const int DEFAULT_BUTTON4 = 0x00000400;
    }
}

but this will more be for consistency with the underlying API. The value is not being used in the implementation that calculates a default button number based on the MessageBoxResult defaultResult.

If the DEFAULT_BUTTON4 should be usefull, it would mean to make a new enum for this and changing all calls to MessageBox.Show to allow the caller to specify a default button instead of a default result. This would look like this:

namespace System.Windows
{
    public enum MessageBoxDefaultBotton
    {
        Button1 = 0x00000000,
        Button2 = 0x00000100,
        Button3 = 0x00000200,
        Button4 = 0x00000400
    }

    public sealed class MessageBox
    {
        public static MessageBoxResult Show(
            string messageBoxText,
            string caption,
            MessageBoxButton button,
            MessageBoxImage icon, 
-           MessageBoxResult defaultResult,
+           MessageBoxDefaultButton defaultButton,
            MessageBoxOptions options,
+           bool displayHelpButton);

}

API Usage

// Fancy the value
var msgBoxResult = System.Windows.MessageBox.Show("My short message", 
    "My app name",
    MessageBoxButton.OkCancel,
    MessageBoxImage.Information,
    MessageBoxResult.Ok,  // Or MessageBoxDefaultButton.Button1
    0, 
    "<Path to my help file>",
    "<Help key word to a more detailed message>");

This will open the help file specified on the key work specified

Alternative Designs

No response

Risks

It must be ensured that a valid handle for sending the WM_HELP message is found (1). This will have to be a part of the ShowCore changes. The implementation in WinForms repository handles it by getting the Active Window if an owner is not specified.

  1. https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox

Metadata

Metadata

Assignees

No one assigned

    Labels

    API suggestionEarly API idea and discussion, it is NOT ready for implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions