summaryrefslogtreecommitdiff
path: root/ui/Taskbar_Seven/taskbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui/Taskbar_Seven/taskbar.cpp')
-rw-r--r--ui/Taskbar_Seven/taskbar.cpp112
1 files changed, 112 insertions, 0 deletions
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 <ShObjIdl.h>
+
+#include <map>
+#include <string>
+#include <comdef.h>
+#include <zen/com_error.h>
+#include <zen/com_ptr.h>
+
+using namespace zen;
+
+
+namespace
+{
+std::wstring lastErrorMessage;
+
+
+ComPtr<ITaskbarList3> getInstance()
+{
+ ComPtr<ITaskbarList3> 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<ITaskbarList3> taskbarlist = getInstance();
+ if (!taskbarlist) //error msg already set
+ return false;
+
+ HRESULT hr = taskbarlist->SetProgressState(static_cast<HWND>(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<ITaskbarList3> taskbarlist = getInstance();
+ if (!taskbarlist) //error msg already set
+ return false;
+
+ HRESULT hr = taskbarlist->SetProgressValue(
+ static_cast<HWND>(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;
+ }
+}
bgstack15