Skip to content

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Aug 29, 2025

Description of Change

Closes #22600.

Fixes Windows message box default button handling.

On Windows, dialog.showMessageBox / showMessageBoxSync ignored defaultId when it was 0 (first button) and failed whenever the target button text matched a common button (OK/Yes/No/Cancel/etc.), because we always offset with kIDStart instead of using the native common button ID. This meant the default focus could be wrong. The fix accepts defaultId >= 0`, bounds‑checks it, and maps to the proper ID (common button ID or custom offset) before calling TaskDialogIndirect.

Using the following code:

dialog.showMessageBoxSync(null, {
    type:'warning',
    buttons: ['Yes', 'No'],
    defaultId: 1,
    cancelId: 1,
    title: 'Power Control',
    message: "Warning!"
});
Before

Screenshot 2025-08-29 at 9 54 35 AM

After

Screenshot 2025-08-29 at 9 54 55 AM

Checklist

Release Notes

Notes: Fixes Windows dialog.showMessageBox default button handling.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/36-x-y PR should also be added to the "36-x-y" branch. target/37-x-y PR should also be added to the "37-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch. labels Aug 29, 2025
@electron-cation electron-cation bot added new-pr 🌱 PR opened recently and removed new-pr 🌱 PR opened recently labels Aug 29, 2025
@github-actions github-actions bot added the target/39-x-y PR should also be added to the "39-x-y" branch. label Sep 3, 2025
@codebytere codebytere requested review from jkleinsc and deepak1556 and removed request for VerteDinde September 5, 2025 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes target/36-x-y PR should also be added to the "36-x-y" branch. target/37-x-y PR should also be added to the "37-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch. target/39-x-y PR should also be added to the "39-x-y" branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dialog.showMessageBoxSync defaultId not work under windows OS.
2 participants