From bd6336c629841c6db3a6ca53a936d629d34db53b Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:15:16 +0200 Subject: 4.1 --- ui/Taskbar_Seven/Taskbar_Seven.vcxproj | 239 +++++++++++++++++++++++++++++++++ ui/Taskbar_Seven/dll_main.cpp | 25 ++++ ui/Taskbar_Seven/taskbar.cpp | 112 +++++++++++++++ ui/Taskbar_Seven/taskbar.h | 72 ++++++++++ 4 files changed, 448 insertions(+) create mode 100644 ui/Taskbar_Seven/Taskbar_Seven.vcxproj create mode 100644 ui/Taskbar_Seven/dll_main.cpp create mode 100644 ui/Taskbar_Seven/taskbar.cpp create mode 100644 ui/Taskbar_Seven/taskbar.h (limited to 'ui/Taskbar_Seven') diff --git a/ui/Taskbar_Seven/Taskbar_Seven.vcxproj b/ui/Taskbar_Seven/Taskbar_Seven.vcxproj new file mode 100644 index 00000000..37786768 --- /dev/null +++ b/ui/Taskbar_Seven/Taskbar_Seven.vcxproj @@ -0,0 +1,239 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {70394AEF-5897-4911-AFA1-82EAF0581EFA} + ShadowDll + Win32Proj + + + + DynamicLibrary + Unicode + true + Windows7.1SDK + + + DynamicLibrary + Unicode + Windows7.1SDK + + + DynamicLibrary + Unicode + true + Windows7.1SDK + + + DynamicLibrary + Unicode + Windows7.1SDK + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + Taskbar7_$(Platform) + Taskbar7_$(Platform) + Taskbar7_$(Platform) + Taskbar7_$(Platform) + + + + $(IntDir)Build.html + + + Disabled + _DEBUG;_WINDOWS;_USRDLL;TASKBAR_SEVEN_DLL_EXPORTS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + true + EditAndContinue + 4100 + ../.. + + + $(OutDir)$(TargetName)$(TargetExt) + true + true + $(IntDir)$(TargetName).pdb + Windows + + + $(IntDir)$(TargetName).lib + MachineX86 + + + + + $(IntDir)Build.html + + + X64 + + + Disabled + _DEBUG;_WINDOWS;_USRDLL;TASKBAR_SEVEN_DLL_EXPORTS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + true + ProgramDatabase + 4100 + ../.. + + + $(OutDir)$(TargetName)$(TargetExt) + true + true + $(IntDir)$(TargetName).pdb + Windows + + + $(IntDir)$(TargetName).lib + MachineX64 + + + + + $(IntDir)Build.html + + + MaxSpeed + true + NDEBUG;_WINDOWS;_USRDLL;TASKBAR_SEVEN_DLL_EXPORTS;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level4 + true + ProgramDatabase + 4100 + Speed + ../.. + + + $(OutDir)$(TargetName)$(TargetExt) + true + false + Windows + true + true + UseLinkTimeCodeGeneration + + + $(IntDir)$(TargetName).lib + MachineX86 + + + + + $(IntDir)Build.html + + + X64 + + + MaxSpeed + true + NDEBUG;_WINDOWS;_USRDLL;TASKBAR_SEVEN_DLL_EXPORTS;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level4 + true + ProgramDatabase + 4100 + Speed + ../.. + + + $(OutDir)$(TargetName)$(TargetExt) + true + false + Windows + true + true + UseLinkTimeCodeGeneration + + + $(IntDir)$(TargetName).lib + MachineX64 + + + + + + + false + + + false + + + false + + + false + + + + + + + + + + \ No newline at end of file diff --git a/ui/Taskbar_Seven/dll_main.cpp b/ui/Taskbar_Seven/dll_main.cpp new file mode 100644 index 00000000..3805c99d --- /dev/null +++ b/ui/Taskbar_Seven/dll_main.cpp @@ -0,0 +1,25 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** + + +#define WIN32_LEAN_AND_MEAN +#include + +//optional: add init/teardown logic here +BOOL APIENTRY DllMain(HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpvReserved) +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + case DLL_PROCESS_DETACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + break; + } + return TRUE; +} diff --git a/ui/Taskbar_Seven/taskbar.cpp b/ui/Taskbar_Seven/taskbar.cpp new file mode 100644 index 00000000..368152f4 --- /dev/null +++ b/ui/Taskbar_Seven/taskbar.cpp @@ -0,0 +1,112 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** + +#include "taskbar.h" + +#define WIN32_LEAN_AND_MEAN +#include "windows.h" +#include + +#include +#include +#include +#include +#include + +using namespace zen; + + +namespace +{ +std::wstring lastErrorMessage; + + +ComPtr getInstance() +{ + ComPtr taskbarlist; + + HRESULT hr = ::CoCreateInstance(CLSID_TaskbarList, + NULL, + CLSCTX_ALL, + IID_PPV_ARGS(taskbarlist.init())); + if (FAILED(hr)) + lastErrorMessage = generateErrorMsg(L"Error calling \"CoCreateInstance\".", hr); + + return taskbarlist; +} +} +//################################################################################################## + + +bool tbseven::setStatus(void* hwnd, //HWND: window assciated to the taskbar icon + TaskBarStatus status) +{ + TBPFLAG flag = TBPF_NORMAL; + switch (status) + { + case STATUS_NOPROGRESS: + flag = TBPF_NOPROGRESS; + break; + case STATUS_INDETERMINATE: + flag = TBPF_INDETERMINATE; + break; + case STATUS_NORMAL: + flag = TBPF_NORMAL; + break; + case STATUS_ERROR: + flag = TBPF_ERROR; + break; + case STATUS_PAUSED: + flag = TBPF_PAUSED; + break; + } + + ComPtr taskbarlist = getInstance(); + if (!taskbarlist) //error msg already set + return false; + + HRESULT hr = taskbarlist->SetProgressState(static_cast(hwnd), //[in] HWND hwnd, + flag); //[in] TBPFLAG tbpFlags + if (FAILED(hr)) + { + lastErrorMessage = generateErrorMsg(L"Error calling \"SetProgressState\".", hr); + return false; + } + + return true; +} + + +bool tbseven::setProgress(void* hwnd, //HWND: window assciated to the taskbar icon + size_t current, + size_t total) +{ + ComPtr taskbarlist = getInstance(); + if (!taskbarlist) //error msg already set + return false; + + HRESULT hr = taskbarlist->SetProgressValue( + static_cast(hwnd), //[in] HWND hwnd, + current, //[in] ULONGLONG ullCompleted, + total); //[in] ULONGLONG ullTotal + if (FAILED(hr)) + { + lastErrorMessage = generateErrorMsg(L"Error calling \"SetProgressValue\".", hr); + return false; + } + + return true; +} + + +void tbseven::getLastError(wchar_t* buffer, size_t bufferSize) +{ + if (bufferSize > 0) + { + size_t endPos = lastErrorMessage.copy(buffer, bufferSize - 1); + buffer[endPos] = 0; + } +} diff --git a/ui/Taskbar_Seven/taskbar.h b/ui/Taskbar_Seven/taskbar.h new file mode 100644 index 00000000..082f463f --- /dev/null +++ b/ui/Taskbar_Seven/taskbar.h @@ -0,0 +1,72 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** + +#ifndef TASKBAR_SEVEN_DLL_H +#define TASKBAR_SEVEN_DLL_H + +#ifdef TASKBAR_SEVEN_DLL_EXPORTS +#define DLL_FUNCTION_DECLARATION extern "C" __declspec(dllexport) +#else +#define DLL_FUNCTION_DECLARATION extern "C" __declspec(dllimport) +#endif + +#include + + +namespace tbseven +{ +/*-------------- + |declarations| + --------------*/ + +enum TaskBarStatus +{ + STATUS_NOPROGRESS, + STATUS_INDETERMINATE, + STATUS_NORMAL, + STATUS_ERROR, + STATUS_PAUSED +}; + + +//COM needs to be initialized before calling any of these functions! CoInitializeEx/CoUninitialize + +DLL_FUNCTION_DECLARATION +bool setStatus(void* hwnd, //HWND: window assciated to the taskbar icon + TaskBarStatus status); + + +DLL_FUNCTION_DECLARATION +bool setProgress(void* hwnd, //HWND: window assciated to the taskbar icon + size_t current, + size_t total); + +//if any of the functions above returns 'false', this message returns last error +DLL_FUNCTION_DECLARATION +void getLastError(wchar_t* buffer, size_t bufferSize); + +/*---------- + |typedefs| + ----------*/ +typedef bool (*SetStatusFct )(void* hwnd, TaskBarStatus status); +typedef bool (*SetProgressFct )(void* hwnd, size_t current, size_t total); +typedef void (*GetLastErrorFct)(wchar_t* buffer, size_t bufferSize); + +/*-------------- + |symbol names| + --------------*/ +//(use const pointers to ensure internal linkage) +const char setStatusFctName [] = "setStatus"; +const char setProgressFctName [] = "setProgress"; +const char getLastErrorFctName[] = "getLastError"; + +/*--------------- + |library names| + ---------------*/ +inline const wchar_t* getDllName() { return zen::is64BitBuild ? L"Taskbar7_x64.dll" : L"Taskbar7_Win32.dll"; } +} + +#endif //TASKBAR_SEVEN_DLL_H -- cgit