From 12efb20ad23815d74fd7bfb14149ee408720fb97 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 28 Oct 2017 23:27:12 +0200 Subject: [PATCH] Disable close title bar button in wxProgressDialog too When the "Cancel" button inside the dialog is disabled, disable the close title bar button as well as it serves the same purpose. In particular, this avoids asserts when clicking the close title bar button while showing the confirmation message box asking the user whether the dialog should be cancelled in the dialogs sample. --- src/msw/progdlg.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/msw/progdlg.cpp b/src/msw/progdlg.cpp index e7063df445..f732dd5bf4 100644 --- a/src/msw/progdlg.cpp +++ b/src/msw/progdlg.cpp @@ -190,6 +190,16 @@ BOOL CALLBACK DisplayCloseButton(HWND hwnd, LPARAM lParam) return TRUE; } +// This function enables or disables both the cancel button in the task dialog +// and the close button in its title bar, as they perform the same function and +// so should be kept in the same state. +void EnableCloseButtons(HWND hwnd, bool enable) +{ + ::SendMessage(hwnd, TDM_ENABLE_BUTTON, IDCANCEL, enable ? TRUE : FALSE); + + wxTopLevelWindow::MSWEnableCloseButton(hwnd, enable); +} + void PerformNotificationUpdates(HWND hwnd, wxProgressDialogSharedData *sharedData) { @@ -315,7 +325,7 @@ void PerformNotificationUpdates(HWND hwnd, ::SendMessage( hwnd, TDM_ENABLE_BUTTON, Id_SkipBtn, TRUE ); if ( sharedData->m_notifications & wxSPDD_ENABLE_ABORT ) - ::SendMessage( hwnd, TDM_ENABLE_BUTTON, IDCANCEL, TRUE ); + EnableCloseButtons(hwnd, true); if ( sharedData->m_notifications & wxSPDD_DISABLE_SKIP ) ::SendMessage( hwnd, TDM_ENABLE_BUTTON, Id_SkipBtn, FALSE ); @@ -329,7 +339,7 @@ void PerformNotificationUpdates(HWND hwnd, { // Change Cancel into Close and activate the button. ::SendMessage( hwnd, TDM_ENABLE_BUTTON, Id_SkipBtn, FALSE ); - ::SendMessage( hwnd, TDM_ENABLE_BUTTON, IDCANCEL, TRUE ); + EnableCloseButtons(hwnd, true); ::EnumChildWindows( hwnd, DisplayCloseButton, (LPARAM) sharedData ); } @@ -1116,7 +1126,7 @@ wxProgressDialogTaskRunner::TaskDialogCallbackProc // If we can't be aborted, the "Close" button will only be enabled // when the progress ends (and not even then with wxPD_AUTO_HIDE). if ( !(sharedData->m_style & wxPD_CAN_ABORT) ) - ::SendMessage( hwnd, TDM_ENABLE_BUTTON, IDCANCEL, FALSE ); + EnableCloseButtons(hwnd, false); break; case TDN_BUTTON_CLICKED: @@ -1151,7 +1161,7 @@ wxProgressDialogTaskRunner::TaskDialogCallbackProc ); ::SendMessage(hwnd, TDM_ENABLE_BUTTON, Id_SkipBtn, FALSE); - ::SendMessage(hwnd, TDM_ENABLE_BUTTON, IDCANCEL, FALSE); + EnableCloseButtons(hwnd, false); sharedData->m_timeStop = wxGetCurrentTime(); sharedData->m_state = wxProgressDialog::Canceled;