Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 163 lines (139 sloc) 4.526 kb
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// 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.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////

#include "WinSevenTaskbar.h"

#include <QWidget>
#include <QIcon>
#include <ShObjIdl.h>

UINT WinSevenTaskbar::m_winMsg = 0;
ITaskbarList3 *WinSevenTaskbar::m_ptbl = NULL;

WinSevenTaskbar::WinSevenTaskbar(void)
{
throw "Cannot create instance of this class!";
}

WinSevenTaskbar::~WinSevenTaskbar(void)
{
}

////////////////////////////////////////////////////////////

#ifdef __ITaskbarList3_INTERFACE_DEFINED__

void WinSevenTaskbar::init(void)
{
m_winMsg = RegisterWindowMessageW(L"TaskbarButtonCreated");
m_ptbl = NULL;
}

void WinSevenTaskbar::uninit(void)
{
if(m_ptbl)
{
m_ptbl->Release();
m_ptbl = NULL;
}
}

bool WinSevenTaskbar::handleWinEvent(MSG *message, long *result)
{
bool stopEvent = false;

if(message->message == m_winMsg)
{
if(!m_ptbl) createInterface();
*result = (m_ptbl) ? S_OK : S_FALSE;
stopEvent = true;
}

return stopEvent;
}

void WinSevenTaskbar::createInterface(void)
{
if(!m_ptbl)
{
ITaskbarList3 *ptbl = NULL;
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ptbl));

if (SUCCEEDED(hr))
{
HRESULT hr2 = ptbl->HrInit();
if(SUCCEEDED(hr2))
{
m_ptbl = ptbl;
/*qDebug("ITaskbarList3::HrInit() succeeded.");*/
}
else
{
ptbl->Release();
qWarning("ITaskbarList3::HrInit() has failed.");
}
}
else
{
qWarning("ITaskbarList3 could not be created.");
}
}
}

bool WinSevenTaskbar::setTaskbarState(QWidget *window, WinSevenTaskbarState state)
{
bool result = false;

if(m_ptbl && window)
{
HRESULT hr = HRESULT(-1);

switch(state)
{
case WinSevenTaskbarNoState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_NOPROGRESS);
break;
case WinSevenTaskbarNormalState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_NORMAL);
break;
case WinSevenTaskbarIndeterminateState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_INDETERMINATE);
break;
case WinSevenTaskbarErrorState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_ERROR);
break;
case WinSevenTaskbarPausedState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_PAUSED);
break;
}

result = SUCCEEDED(hr);
}

return result;
}

void WinSevenTaskbar::setTaskbarProgress(QWidget *window, unsigned __int64 currentValue, unsigned __int64 maximumValue)
{
if(m_ptbl && window)
{
m_ptbl->SetProgressValue(reinterpret_cast<HWND>(window->winId()), currentValue, maximumValue);
}
}

void WinSevenTaskbar::setOverlayIcon(QWidget *window, QIcon *icon)
{
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
if(m_ptbl && window)
{
m_ptbl->SetOverlayIcon(window->winId(), (icon ? icon->pixmap(16,16).toWinHICON() : NULL), L"LameXP");
}
#endif
}

#else //__ITaskbarList3_INTERFACE_DEFINED__

LAMEXP_COMPILER_WARNING("ITaskbarList3 not defined. Compiling *without* support for Win7 taskbar!")
void WinSevenTaskbar::init(void) {}
void WinSevenTaskbar::uninit(void) {}
bool WinSevenTaskbar::handleWinEvent(MSG *message, long *result) { return false; }
void WinSevenTaskbar::createInterface(void) {}
bool WinSevenTaskbar::setTaskbarState(QWidget *window, WinSevenTaskbarState state) { return false; }
void WinSevenTaskbar::setTaskbarProgress(QWidget *window, unsigned __int64 currentValue, unsigned __int64 maximumValue) {}
void WinSevenTaskbar::setOverlayIcon(QWidget *window, QIcon *icon) {}

#endif //__ITaskbarList3_INTERFACE_DEFINED__
Something went wrong with that request. Please try again.