diff --git a/src/core/windows7thumbbar.cpp b/src/core/windows7thumbbar.cpp index 127cd67c3..adbe560df 100644 --- a/src/core/windows7thumbbar.cpp +++ b/src/core/windows7thumbbar.cpp @@ -49,7 +49,8 @@ Windows7ThumbBar::Windows7ThumbBar(QWidget *widget) : QObject(widget), widget_(widget), timer_(new QTimer(this)), - button_created_message_id_(0) { + button_created_message_id_(0), + taskbar_list_(nullptr) { timer_->setSingleShot(true); timer_->setInterval(300); @@ -130,8 +131,12 @@ void Windows7ThumbBar::HandleWinEvent(MSG *msg) { if (msg->message == button_created_message_id_) { - ITaskbarList3 *taskbar_list = CreateTaskbarList(); - if (!taskbar_list) return; + if (taskbar_list_) { + taskbar_list_->Release(); + } + + taskbar_list_ = CreateTaskbarList(); + if (!taskbar_list_) return; // Add the buttons THUMBBUTTON buttons[kMaxButtonCount]; @@ -143,7 +148,7 @@ void Windows7ThumbBar::HandleWinEvent(MSG *msg) { } qLog(Debug) << "Adding" << actions_.count() << "buttons"; - HRESULT hr = taskbar_list->ThumbBarAddButtons(reinterpret_cast(widget_->winId()), actions_.count(), buttons); + HRESULT hr = taskbar_list_->ThumbBarAddButtons(reinterpret_cast(widget_->winId()), actions_.count(), buttons); if (hr != S_OK) { qLog(Debug) << "Failed to add buttons" << Qt::hex << DWORD(hr); } @@ -154,8 +159,6 @@ void Windows7ThumbBar::HandleWinEvent(MSG *msg) { } } - taskbar_list->Release(); - } else if (msg->message == WM_COMMAND) { const int button_id = LOWORD(msg->wParam); @@ -176,8 +179,7 @@ void Windows7ThumbBar::ActionChangedTriggered() { void Windows7ThumbBar::ActionChanged() { - ITaskbarList3 *taskbar_list = CreateTaskbarList(); - if (!taskbar_list) return; + if (!taskbar_list_) return; qLog(Debug) << "Updating" << actions_.count() << "buttons"; @@ -190,7 +192,7 @@ void Windows7ThumbBar::ActionChanged() { SetupButton(action, button); } - HRESULT hr = taskbar_list->ThumbBarUpdateButtons(reinterpret_cast(widget_->winId()), actions_.count(), buttons); + HRESULT hr = taskbar_list_->ThumbBarUpdateButtons(reinterpret_cast(widget_->winId()), actions_.count(), buttons); if (hr != S_OK) { qLog(Debug) << "Failed to update buttons" << Qt::hex << DWORD(hr); } @@ -201,6 +203,4 @@ void Windows7ThumbBar::ActionChanged() { } } - taskbar_list->Release(); - } diff --git a/src/core/windows7thumbbar.h b/src/core/windows7thumbbar.h index afc8965b2..43fcf91ca 100644 --- a/src/core/windows7thumbbar.h +++ b/src/core/windows7thumbbar.h @@ -62,6 +62,8 @@ class Windows7ThumbBar : public QObject { QList actions_; unsigned int button_created_message_id_; + + ITaskbarList3 *taskbar_list_; }; #endif // WINDOWS7THUMBBAR_H