From af55e45ce83411f6ce940d76630ae2aaf16bb02c Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 10:02:29 +0200 Subject: [PATCH] fix: `dialog.showMessageBox` defaultid on Windows (#48519) * fix: dialog.showMessageBox defaultid on Windows Co-authored-by: Shelley Vohr * Update shell/browser/ui/message_box_win.cc Co-authored-by: Robo Co-authored-by: Shelley Vohr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- shell/browser/ui/message_box_win.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/shell/browser/ui/message_box_win.cc b/shell/browser/ui/message_box_win.cc index 9ba64cb3f9..88775b0446 100644 --- a/shell/browser/ui/message_box_win.cc +++ b/shell/browser/ui/message_box_win.cc @@ -163,8 +163,19 @@ DialogResult ShowTaskDialogWstr(gfx::AcceleratedWidget parent, config.dwFlags |= TDF_POSITION_RELATIVE_TO_WINDOW; } - if (default_id > 0) - config.nDefaultButton = kIDStart + default_id; + if (default_id >= 0 && + base::checked_cast(default_id) < buttons.size()) { + if (!no_link) { + auto common = GetCommonID(buttons[default_id]); + if (common.button != -1) { + config.nDefaultButton = common.id; + } else { + config.nDefaultButton = kIDStart + default_id; + } + } else { + config.nDefaultButton = kIDStart + default_id; + } + } // TaskDialogIndirect doesn't allow empty name, if we set empty title it // will show "electron.exe" in title.