
Originally Posted by
ManicQin
faldżip like you said, I was talking about using the task bar new features, especially the progress notification... I've seen tutorials about how to work them with visual studio 10... (apparently the sdk is already included)
You have to request the system for a proper task bar using the function RegisterWindowMessage, then you wait for a response in the member function QWidget::winEvent. Then, you can create the task bar and use it.
Maybe you could understand better this small example I wrote.
Have also a look at the functions ITaskbarList3::SetProgressState and ITaskbarList3::SetProgressValue.
Unfortunately I do not know much about using other features of new task bars.
TEMPLATE = app
LIBS += User32.lib
LIBS += Ole32.lib
HEADERS += ProgressDialog.h
SOURCES += ProgressDialog.cpp
TEMPLATE = app
LIBS += User32.lib
LIBS += Ole32.lib
HEADERS += ProgressDialog.h
SOURCES += ProgressDialog.cpp
To copy to clipboard, switch view to plain text mode
#include <QDialog>
#include <QTimer>
#include <windows.h>
#include <shobjidl.h>
class ProgressDialog
: public QDialog{
Q_OBJECT
public:
ProgressDialog
(QWidget *parent
= 0);
protected:
bool winEvent(MSG * message, long * result);
private:
void setupProgressBar();
private slots:
void updateProgress();
private:
int progress;
int totalProgress;
bool canUseTaskBar;
UINT taskBarCreatedMessage;
ITaskbarList3 * taskbar;
};
#include <QDialog>
#include <QTimer>
#include <windows.h>
#include <shobjidl.h>
class ProgressDialog : public QDialog
{
Q_OBJECT
public:
ProgressDialog(QWidget *parent = 0);
protected:
bool winEvent(MSG * message, long * result);
private:
void setupProgressBar();
private slots:
void updateProgress();
private:
QTimer timer;
int progress;
int totalProgress;
bool canUseTaskBar;
UINT taskBarCreatedMessage;
ITaskbarList3 * taskbar;
};
To copy to clipboard, switch view to plain text mode
#include "ProgressDialog.h"
#include <shobjidl.h>
#include <Objbase.h>
#include <QApplication>
int main(int argc, char *argv[])
{
ProgressDialog d;
d.show();
return a.exec();
}
ProgressDialog
::ProgressDialog(QWidget *parent
) :{
this->progress = 0;
this->totalProgress = 1000;
this->canUseTaskBar = false;
this->timer.setInterval(10);
this->connect( & this->timer, SIGNAL(timeout()), this, SLOT(updateProgress()));
// Request task bar.
this->taskBarCreatedMessage = RegisterWindowMessage(L"TaskbarButtonCreated");
}
bool ProgressDialog::winEvent(MSG * message, long * result)
{
if (message->message == this->taskBarCreatedMessage)
{
HRESULT hr = CoCreateInstance(CLSID_TaskbarList,
0,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS( & this->taskbar));
if (hr == S_OK) {
this->canUseTaskBar = true;
// Start progress.
this->setupProgressBar();
this->timer.start();
} else {
this->canUseTaskBar = false;
// Error.
}
*result = hr;
return true;
}
return false;
}
void ProgressDialog::setupProgressBar()
{
if (this->canUseTaskBar) {
// Select the progress bar type.
// One of these:
// No progress bar.
// this->taskbar->SetProgressState(this->winId(), TBPF_NOPROGRESS);
// Unknown progress.
// this->taskbar->SetProgressState(this->winId(), TBPF_INDETERMINATE);
// Normal progress (green bar).
this->taskbar->SetProgressState(this->winId(), TBPF_NORMAL);
// Paused (yellow bar).
// this->taskbar->SetProgressState(this->winId(), TBPF_PAUSED);
// Error (red bar).
// this->taskbar->SetProgressState(this->winId(), TBPF_ERROR);
}
}
void ProgressDialog::updateProgress()
{
if (this->canUseTaskBar) {
// Set progress.
this->taskbar->SetProgressValue(this->winId(), this->progress, this->totalProgress);
progress++;
}
}
#include "ProgressDialog.h"
#include <shobjidl.h>
#include <Objbase.h>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ProgressDialog d;
d.show();
return a.exec();
}
ProgressDialog::ProgressDialog(QWidget *parent) :
QDialog(parent)
{
this->progress = 0;
this->totalProgress = 1000;
this->canUseTaskBar = false;
this->timer.setInterval(10);
this->connect( & this->timer, SIGNAL(timeout()), this, SLOT(updateProgress()));
// Request task bar.
this->taskBarCreatedMessage = RegisterWindowMessage(L"TaskbarButtonCreated");
}
bool ProgressDialog::winEvent(MSG * message, long * result)
{
if (message->message == this->taskBarCreatedMessage)
{
HRESULT hr = CoCreateInstance(CLSID_TaskbarList,
0,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS( & this->taskbar));
if (hr == S_OK) {
this->canUseTaskBar = true;
// Start progress.
this->setupProgressBar();
this->timer.start();
} else {
this->canUseTaskBar = false;
// Error.
}
*result = hr;
return true;
}
return false;
}
void ProgressDialog::setupProgressBar()
{
if (this->canUseTaskBar) {
// Select the progress bar type.
// One of these:
// No progress bar.
// this->taskbar->SetProgressState(this->winId(), TBPF_NOPROGRESS);
// Unknown progress.
// this->taskbar->SetProgressState(this->winId(), TBPF_INDETERMINATE);
// Normal progress (green bar).
this->taskbar->SetProgressState(this->winId(), TBPF_NORMAL);
// Paused (yellow bar).
// this->taskbar->SetProgressState(this->winId(), TBPF_PAUSED);
// Error (red bar).
// this->taskbar->SetProgressState(this->winId(), TBPF_ERROR);
}
}
void ProgressDialog::updateProgress()
{
if (this->canUseTaskBar) {
// Set progress.
this->taskbar->SetProgressValue(this->winId(), this->progress, this->totalProgress);
progress++;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks