forked from arthurzam/dukto-qt5
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathecwin7.cpp
96 lines (89 loc) · 3.26 KB
/
ecwin7.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* EcWin7 - Support library for integrating Windows 7 taskbar features
* into any Qt application
* Copyright (C) 2010 Emanuele Colombo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "ecwin7.h"
// Windows only GUID definitions
#if defined(Q_OS_WIN)
DEFINE_GUID(CLSID_TaskbarList,0x56fdf344,0xfd6d,0x11d0,0x95,0x8a,0x0,0x60,0x97,0xc9,0xa0,0x90);
DEFINE_GUID(IID_ITaskbarList3,0xea1afb91,0x9e28,0x4b86,0x90,0xE9,0x9e,0x9f,0x8a,0x5e,0xef,0xaf);
// Constructor: variabiles initialization
EcWin7::EcWin7(QWindow *window)
{
#ifdef Q_OS_WIN
mWindowId = reinterpret_cast<HWND>(window->winId());
mTaskbarMessageId = RegisterWindowMessage(L"TaskbarButtonCreated");
#else
Q_UNUSED(window)
#endif
}
// Windows event handler callback function
// (handles taskbar communication initial message)
bool EcWin7::winEvent(MSG * message, long * result)
{
if (message->message == mTaskbarMessageId)
{
HRESULT hr = CoCreateInstance(CLSID_TaskbarList,
0,
CLSCTX_INPROC_SERVER,
IID_ITaskbarList3,
reinterpret_cast<void**> (&(mTaskbar)));
*result = hr;
return true;
}
return false;
}
// Set progress bar current value
void EcWin7::setProgressValue(int value, int max)
{
if (!mTaskbar) return;
mTaskbar->SetProgressValue(mWindowId, value, max);
}
// Set progress bar current state (active, error, pause, ecc...)
void EcWin7::setProgressState(ToolBarProgressState state)
{
if (!mTaskbar) return;
mTaskbar->SetProgressState(mWindowId, (TBPFLAG)state);
}
// Set new overlay icon and corresponding description (for accessibility)
// (call with iconName == "" and description == "" to remove any previous overlay icon)
void EcWin7::setOverlayIcon(const QString &iconName, const QString &description)
{
if (!mTaskbar) return;
HICON oldIcon = nullptr;
if (mOverlayIcon != nullptr) oldIcon = mOverlayIcon;
if (iconName.isEmpty())
{
mTaskbar->SetOverlayIcon(mWindowId, nullptr, nullptr);
mOverlayIcon = nullptr;
}
else
{
mOverlayIcon = (HICON) LoadImage(GetModuleHandle(nullptr),
iconName.toStdWString().c_str(),
IMAGE_ICON,
0,
0,
0);
mTaskbar->SetOverlayIcon(mWindowId, mOverlayIcon, description.toStdWString().c_str());
}
if ((oldIcon != nullptr) && (oldIcon != mOverlayIcon))
{
DestroyIcon(oldIcon);
}
}
#endif