Windows7ThumbBar: Create taskbar list once
This commit is contained in:
parent
4935cdc722
commit
fd9ab43681
@ -49,7 +49,8 @@ Windows7ThumbBar::Windows7ThumbBar(QWidget *widget)
|
|||||||
: QObject(widget),
|
: QObject(widget),
|
||||||
widget_(widget),
|
widget_(widget),
|
||||||
timer_(new QTimer(this)),
|
timer_(new QTimer(this)),
|
||||||
button_created_message_id_(0) {
|
button_created_message_id_(0),
|
||||||
|
taskbar_list_(nullptr) {
|
||||||
|
|
||||||
timer_->setSingleShot(true);
|
timer_->setSingleShot(true);
|
||||||
timer_->setInterval(300);
|
timer_->setInterval(300);
|
||||||
@ -130,8 +131,12 @@ void Windows7ThumbBar::HandleWinEvent(MSG *msg) {
|
|||||||
|
|
||||||
if (msg->message == button_created_message_id_) {
|
if (msg->message == button_created_message_id_) {
|
||||||
|
|
||||||
ITaskbarList3 *taskbar_list = CreateTaskbarList();
|
if (taskbar_list_) {
|
||||||
if (!taskbar_list) return;
|
taskbar_list_->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
taskbar_list_ = CreateTaskbarList();
|
||||||
|
if (!taskbar_list_) return;
|
||||||
|
|
||||||
// Add the buttons
|
// Add the buttons
|
||||||
THUMBBUTTON buttons[kMaxButtonCount];
|
THUMBBUTTON buttons[kMaxButtonCount];
|
||||||
@ -143,7 +148,7 @@ void Windows7ThumbBar::HandleWinEvent(MSG *msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
qLog(Debug) << "Adding" << actions_.count() << "buttons";
|
qLog(Debug) << "Adding" << actions_.count() << "buttons";
|
||||||
HRESULT hr = taskbar_list->ThumbBarAddButtons(reinterpret_cast<HWND>(widget_->winId()), actions_.count(), buttons);
|
HRESULT hr = taskbar_list_->ThumbBarAddButtons(reinterpret_cast<HWND>(widget_->winId()), actions_.count(), buttons);
|
||||||
if (hr != S_OK) {
|
if (hr != S_OK) {
|
||||||
qLog(Debug) << "Failed to add buttons" << Qt::hex << DWORD(hr);
|
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) {
|
else if (msg->message == WM_COMMAND) {
|
||||||
const int button_id = LOWORD(msg->wParam);
|
const int button_id = LOWORD(msg->wParam);
|
||||||
@ -176,8 +179,7 @@ void Windows7ThumbBar::ActionChangedTriggered() {
|
|||||||
|
|
||||||
void Windows7ThumbBar::ActionChanged() {
|
void Windows7ThumbBar::ActionChanged() {
|
||||||
|
|
||||||
ITaskbarList3 *taskbar_list = CreateTaskbarList();
|
if (!taskbar_list_) return;
|
||||||
if (!taskbar_list) return;
|
|
||||||
|
|
||||||
qLog(Debug) << "Updating" << actions_.count() << "buttons";
|
qLog(Debug) << "Updating" << actions_.count() << "buttons";
|
||||||
|
|
||||||
@ -190,7 +192,7 @@ void Windows7ThumbBar::ActionChanged() {
|
|||||||
SetupButton(action, button);
|
SetupButton(action, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT hr = taskbar_list->ThumbBarUpdateButtons(reinterpret_cast<HWND>(widget_->winId()), actions_.count(), buttons);
|
HRESULT hr = taskbar_list_->ThumbBarUpdateButtons(reinterpret_cast<HWND>(widget_->winId()), actions_.count(), buttons);
|
||||||
if (hr != S_OK) {
|
if (hr != S_OK) {
|
||||||
qLog(Debug) << "Failed to update buttons" << Qt::hex << DWORD(hr);
|
qLog(Debug) << "Failed to update buttons" << Qt::hex << DWORD(hr);
|
||||||
}
|
}
|
||||||
@ -201,6 +203,4 @@ void Windows7ThumbBar::ActionChanged() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taskbar_list->Release();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,8 @@ class Windows7ThumbBar : public QObject {
|
|||||||
QList<QAction*> actions_;
|
QList<QAction*> actions_;
|
||||||
|
|
||||||
unsigned int button_created_message_id_;
|
unsigned int button_created_message_id_;
|
||||||
|
|
||||||
|
ITaskbarList3 *taskbar_list_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WINDOWS7THUMBBAR_H
|
#endif // WINDOWS7THUMBBAR_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user