-
Notifications
You must be signed in to change notification settings - Fork 1
/
externalprogressbar_win.cpp
108 lines (81 loc) · 2.97 KB
/
externalprogressbar_win.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
////////////////////////////////////////////////////////////////////////////////
// Windows implementation of ExternalProgressBar
#include <QWidget>
#include "externalprogressbar.h"
// Class with platform-specific data
class ExternalProgressBarPrivate
{
public:
ExternalProgressBarPrivate();
~ExternalProgressBarPrivate();
// Windows7 Taskbar interface for mirroring the progress bar
ITaskbarList3* m_Win7TaskbarList;
// Main window handle for selecting the correct taskbar button
HWND m_hWnd;
};
ExternalProgressBarPrivate::ExternalProgressBarPrivate() :
m_Win7TaskbarList(NULL),
m_hWnd(NULL)
{
}
ExternalProgressBarPrivate::~ExternalProgressBarPrivate()
{
}
ExternalProgressBar::ExternalProgressBar(QWidget* mainWindow) :
d_ptr(new ExternalProgressBarPrivate()),
m_MaxValue(0)
{
// Get the taskbar object (if NULL is returned it won't be used - e.g. on pre-7 Windows versions)
CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_ALL, IID_ITaskbarList3, reinterpret_cast<void**>(&d_ptr->m_Win7TaskbarList));
// Store the window handle. In Windows winId() returns HWND.
d_ptr->m_hWnd = reinterpret_cast<HWND>(mainWindow->winId());
}
ExternalProgressBar::~ExternalProgressBar()
{
DestroyProgressBar();
if (d_ptr->m_Win7TaskbarList != NULL)
d_ptr->m_Win7TaskbarList->Release();
delete d_ptr;
}
// Initializes the external progress bar and sets its limits
bool ExternalProgressBar::InitProgressBar(quint64 maxSteps)
{
bool res = true;
m_MaxValue = maxSteps;
// When we set the progress value, TBPF_NORMAL is set automatically
if (d_ptr->m_Win7TaskbarList != NULL)
res = (d_ptr->m_Win7TaskbarList->SetProgressValue(d_ptr->m_hWnd, 0, maxSteps) == S_OK);
return res;
}
// Deinitializes the external progress bar and returns into the normal state
bool ExternalProgressBar::DestroyProgressBar()
{
bool res = true;
if (d_ptr->m_Win7TaskbarList != NULL)
res = (d_ptr->m_Win7TaskbarList->SetProgressState(d_ptr->m_hWnd, TBPF_NOPROGRESS) == S_OK);
return res;
}
// Updates the current progress bar position
bool ExternalProgressBar::SetProgressValue(quint64 currentSteps)
{
bool res = true;
if (d_ptr->m_Win7TaskbarList != NULL)
res = (d_ptr->m_Win7TaskbarList->SetProgressValue(d_ptr->m_hWnd, currentSteps, m_MaxValue) == S_OK);
return res;
}
// Sets the progress bar to indicate pause
bool ExternalProgressBar::ProgressSetPause()
{
bool res = true;
if (d_ptr->m_Win7TaskbarList != NULL)
res = (d_ptr->m_Win7TaskbarList->SetProgressState(d_ptr->m_hWnd, TBPF_PAUSED) == S_OK);
return res;
}
// Sets the progress bar to indicate an error
bool ExternalProgressBar::ProgressSetError()
{
bool res = true;
if (d_ptr->m_Win7TaskbarList != NULL)
res = (d_ptr->m_Win7TaskbarList->SetProgressState(d_ptr->m_hWnd, TBPF_ERROR) == S_OK);
return res;
}