2011-04-03 21:50:44 +02:00
|
|
|
/* 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 definitions
|
2012-01-28 12:02:37 +01:00
|
|
|
#ifdef W7TASKBAR
|
2011-11-06 17:01:23 +01:00
|
|
|
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);
|
2011-04-03 21:50:44 +02:00
|
|
|
|
|
|
|
// Constructor: variabiles initialization
|
|
|
|
EcWin7::EcWin7()
|
|
|
|
{
|
2011-11-09 16:58:25 +01:00
|
|
|
mTaskbar = NULL;
|
2011-04-03 21:50:44 +02:00
|
|
|
mOverlayIcon = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init taskbar communication
|
2013-01-19 23:22:30 +01:00
|
|
|
void EcWin7::init(HWND wid)
|
2011-04-03 21:50:44 +02:00
|
|
|
{
|
|
|
|
mWindowId = wid;
|
|
|
|
mTaskbarMessageId = RegisterWindowMessage(L"TaskbarButtonCreated");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Windows event handler callback function
|
|
|
|
// (handles taskbar communication initial message)
|
2011-11-06 17:01:23 +01:00
|
|
|
bool EcWin7::winEvent(MSG* message, long* result)
|
2011-04-03 21:50:44 +02:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (message->message == mTaskbarMessageId) {
|
2011-04-03 21:50:44 +02:00
|
|
|
HRESULT hr = CoCreateInstance(CLSID_TaskbarList,
|
|
|
|
0,
|
|
|
|
CLSCTX_INPROC_SERVER,
|
|
|
|
IID_ITaskbarList3,
|
2011-11-06 17:01:23 +01:00
|
|
|
reinterpret_cast<void**>(&(mTaskbar)));
|
2011-04-03 21:50:44 +02:00
|
|
|
*result = hr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set progress bar current value
|
|
|
|
void EcWin7::setProgressValue(int value, int max)
|
|
|
|
{
|
|
|
|
mTaskbar->SetProgressValue(mWindowId, value, max);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set progress bar current state (active, error, pause, ecc...)
|
|
|
|
void EcWin7::setProgressState(ToolBarProgressState state)
|
|
|
|
{
|
|
|
|
mTaskbar->SetProgressState(mWindowId, (TBPFLAG)state);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
HICON oldIcon = NULL;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (mOverlayIcon != NULL) {
|
|
|
|
oldIcon = mOverlayIcon;
|
|
|
|
}
|
2012-09-02 11:42:41 +02:00
|
|
|
if (iconName.isEmpty()) {
|
2011-04-03 21:50:44 +02:00
|
|
|
mTaskbar->SetOverlayIcon(mWindowId, NULL, NULL);
|
|
|
|
mOverlayIcon = NULL;
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
else {
|
2011-04-03 21:50:44 +02:00
|
|
|
mOverlayIcon = (HICON) LoadImage(GetModuleHandle(NULL),
|
2011-11-06 17:01:23 +01:00
|
|
|
iconName.toStdWString().c_str(),
|
|
|
|
IMAGE_ICON,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL);
|
2011-04-03 21:50:44 +02:00
|
|
|
mTaskbar->SetOverlayIcon(mWindowId, mOverlayIcon, description.toStdWString().c_str());
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
if ((oldIcon != NULL) && (oldIcon != mOverlayIcon)) {
|
2011-04-03 21:50:44 +02:00
|
|
|
DestroyIcon(oldIcon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|