From 49da74f9764bb6efbe1b573430fffcced0d21b01 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 8 Jul 2015 14:35:28 +0800 Subject: [PATCH] Handle when dialog is cancelled --- atom/browser/ui/message_box_win.cc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/atom/browser/ui/message_box_win.cc b/atom/browser/ui/message_box_win.cc index 0811db26fcd0..046efeb62563 100644 --- a/atom/browser/ui/message_box_win.cc +++ b/atom/browser/ui/message_box_win.cc @@ -17,6 +17,10 @@ namespace atom { namespace { +// Small command ID values are already taken by Windows, we have to start from +// a large number to avoid conflicts with Windows. +const int kIDStart = 100; + int ShowMessageBoxUTF16(HWND parent, const std::vector& buttons, int cancel_id, @@ -25,13 +29,17 @@ int ShowMessageBoxUTF16(HWND parent, const base::string16& detail) { std::vector dialog_buttons; for (size_t i = 0; i < buttons.size(); ++i) - dialog_buttons.push_back({i, buttons[i].c_str()}); + dialog_buttons.push_back({i + kIDStart, buttons[i].c_str()}); + + TASKDIALOG_FLAGS flags = TDF_SIZE_TO_CONTENT; + if (cancel_id != 0) + flags |= TDF_ALLOW_DIALOG_CANCELLATION; TASKDIALOGCONFIG config = { 0 }; config.cbSize = sizeof(config); config.hwndParent = parent; config.hInstance = GetModuleHandle(NULL); - config.dwFlags = TDF_SIZE_TO_CONTENT; + config.dwFlags = flags; config.pszWindowTitle = title.c_str(); config.pszMainInstruction = message.c_str(); config.pszContent = detail.c_str(); @@ -40,7 +48,10 @@ int ShowMessageBoxUTF16(HWND parent, int id = 0; TaskDialogIndirect(&config, &id, NULL, NULL); - return id; + if (id == 0 || id == IDCANCEL) + return cancel_id; + else + return id - kIDStart; } void RunMessageBoxInNewThread(base::Thread* thread,