-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecwin7.cpp
111 lines (103 loc) · 3.37 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* 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_WS_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);
#endif
// Constructor: variabiles initialization
EcWin7::EcWin7()
{
#ifdef Q_WS_WIN
mTaskbar = NULL;
mOverlayIcon = NULL;
#endif
}
// Init taskbar communication
void EcWin7::init(WId wid)
{
mWindowId = wid;
#ifdef Q_WS_WIN
mTaskbarMessageId = RegisterWindowMessage(L"TaskbarButtonCreated");
#endif
}
// Windows event handler callback function
// (handles taskbar communication initial message)
#ifdef Q_WS_WIN
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;
}
#endif
// Set progress bar current value
void EcWin7::setProgressValue(int value, int max)
{
#ifdef Q_WS_WIN
if (!mTaskbar) return;
mTaskbar->SetProgressValue(mWindowId, value, max);
#endif
}
// Set progress bar current state (active, error, pause, ecc...)
void EcWin7::setProgressState(ToolBarProgressState state)
{
#ifdef Q_WS_WIN
if (!mTaskbar) return;
mTaskbar->SetProgressState(mWindowId, (TBPFLAG)state);
#endif
}
// Set new overlay icon and corresponding description (for accessibility)
// (call with iconName == "" and description == "" to remove any previous overlay icon)
void EcWin7::setOverlayIcon(QString iconName, QString description)
{
#ifdef Q_WS_WIN
if (!mTaskbar) return;
HICON oldIcon = NULL;
if (mOverlayIcon != NULL) oldIcon = mOverlayIcon;
if (iconName == "")
{
mTaskbar->SetOverlayIcon(mWindowId, NULL, NULL);
mOverlayIcon = NULL;
}
else
{
mOverlayIcon = (HICON) LoadImage(GetModuleHandle(NULL),
iconName.toStdWString().c_str(),
IMAGE_ICON,
0,
0,
NULL);
mTaskbar->SetOverlayIcon(mWindowId, mOverlayIcon, description.toStdWString().c_str());
}
if ((oldIcon != NULL) && (oldIcon != mOverlayIcon))
{
DestroyIcon(oldIcon);
}
#endif
}