forked from maz-1/dukto-qt5
-
Notifications
You must be signed in to change notification settings - Fork 8
/
ecwin7.cpp
107 lines (96 loc) · 4.08 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
/* 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"
#if defined(Q_OS_WIN)
#include <QLibrary>
// Windows only GUID definitions
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);
#ifndef MSGFLT_ALLOW
#define MSGFLT_ALLOW 1
#endif
typedef BOOL (WINAPI *ChangeWindowMessageFilterExFunc)(HWND,UINT,DWORD,PVOID); // Win7+
typedef BOOL (WINAPI *ChangeWindowMessageFilterFunc)(UINT,DWORD); // WinVista+
// Constructor: variabiles initialization
EcWin7::EcWin7(QWindow *window)
{
mWindowId = reinterpret_cast<HWND>(window->winId());
mTaskbarMessageId = RegisterWindowMessage(L"TaskbarButtonCreated");
// for process with elevated privileges
QLibrary lib("user32.dll");
ChangeWindowMessageFilterExFunc pChangeWindowMessageFilterEx = reinterpret_cast<ChangeWindowMessageFilterExFunc>(lib.resolve("ChangeWindowMessageFilterEx"));
if (pChangeWindowMessageFilterEx != nullptr) {
pChangeWindowMessageFilterEx(mWindowId, mTaskbarMessageId, MSGFLT_ALLOW, NULL);
} else {
ChangeWindowMessageFilterFunc pChangeWindowMessageFilter = reinterpret_cast<ChangeWindowMessageFilterFunc>(lib.resolve("ChangeWindowMessageFilter"));
if (pChangeWindowMessageFilter != nullptr) {
pChangeWindowMessageFilter(mTaskbarMessageId, MSGFLT_ALLOW);
}
}
}
// Windows event handler callback function
// (handles taskbar communication initial message)
bool EcWin7::winEvent(MSG * message, void * result)
{
if (message->message == mTaskbarMessageId)
{
HRESULT hr = CoCreateInstance(CLSID_TaskbarList,
0,
CLSCTX_INPROC_SERVER,
IID_ITaskbarList3,
reinterpret_cast<void**>(&mTaskbar));
*static_cast<HRESULT *>(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 == "" to remove any previous overlay icon)
void EcWin7::setOverlayIcon(const QString &iconName, const QString &description)
{
if (!mTaskbar) return;
if (iconName.isEmpty())
{
mTaskbar->SetOverlayIcon(mWindowId, nullptr, nullptr);
}
else
{
HICON overlayIcon = static_cast<HICON>(LoadImage(GetModuleHandle(nullptr),
iconName.toStdWString().c_str(),
IMAGE_ICON,
0,
0,
0));
mTaskbar->SetOverlayIcon(mWindowId, overlayIcon, description.toStdWString().c_str());
DestroyIcon(overlayIcon);
}
}
#endif