diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:08:42 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:08:42 +0200 |
commit | c32707148292d104c66276b43796d6057c8c7a5d (patch) | |
tree | bb83513f4aff24153e21a4ec92e34e4c27651b1f /shared/Taskbar_Seven/taskbar.cpp | |
parent | 3.9 (diff) | |
download | FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.tar.gz FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.tar.bz2 FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.zip |
3.10
Diffstat (limited to 'shared/Taskbar_Seven/taskbar.cpp')
-rw-r--r-- | shared/Taskbar_Seven/taskbar.cpp | 112 |
1 files changed, 42 insertions, 70 deletions
diff --git a/shared/Taskbar_Seven/taskbar.cpp b/shared/Taskbar_Seven/taskbar.cpp index c9a2e7df..d1b1638c 100644 --- a/shared/Taskbar_Seven/taskbar.cpp +++ b/shared/Taskbar_Seven/taskbar.cpp @@ -11,69 +11,41 @@ #include <ShObjIdl.h> #include <map> -#include <string> +#include <string> #include <comdef.h> #include "../com_error.h" +#include "../com_ptr.h" +#include "../c_dll.h" -namespace -{ -void writeString(const std::wstring& input, wchar_t* output, size_t outputBufferLen) -{ - const size_t newSize = min(input.length() + 1, outputBufferLen); //including null-termination - memcpy(output, input.c_str(), newSize * sizeof(wchar_t)); - output[newSize-1] = 0; //if output buffer is too small... -} +using namespace util; +using namespace c_dll; -using Util::generateErrorMsg; -using TaskbarSeven::TBHandle; -typedef std::map<TBHandle, ITaskbarList3*> TaskBarHandleMap; - -TaskbarSeven::TBHandle generateHandle() +namespace { - static TBHandle handle = 0; - return ++handle; //don't return 0! 0 is reserved for indicating failure -} - -TaskBarHandleMap taskBarHandles; - std::wstring lastErrorMessage; -} -//################################################################################################## -TaskbarSeven::TBHandle TaskbarSeven::init() //call on app initializaiton; returns handle +ComPtr<ITaskbarList3> getInstance() { - ITaskbarList3* pto = NULL; - HRESULT hr = CoCreateInstance(CLSID_TaskbarList, - NULL, - CLSCTX_ALL, - IID_PPV_ARGS(&pto)); - if (FAILED(hr)) + static ComPtr<ITaskbarList3> taskbarlist; + if (!taskbarlist) { - lastErrorMessage = generateErrorMsg(L"Error calling \"CoCreateInstance\".", hr); - return 0; + HRESULT hr = CoCreateInstance(CLSID_TaskbarList, + NULL, + CLSCTX_ALL, + IID_PPV_ARGS(taskbarlist.init())); + if (FAILED(hr)) + lastErrorMessage = generateErrorMsg(L"Error calling \"CoCreateInstance\".", hr); } - TBHandle newHandle = ::generateHandle(); - taskBarHandles[newHandle] = pto; - return newHandle; + return taskbarlist; } - -void TaskbarSeven::release(TBHandle handle) //release handle on app exit -{ - TaskBarHandleMap::const_iterator iter = taskBarHandles.find(handle); - if (iter != taskBarHandles.end()) - { - if (iter->second != NULL) - iter->second->Release(); - taskBarHandles.erase(iter); - } } +//################################################################################################## -bool TaskbarSeven::setStatus(TBHandle handle, - void* hwnd, //HWND: window assciated to the taskbar icon +bool tbseven::setStatus(void* hwnd, //HWND: window assciated to the taskbar icon TaskBarStatus status) { TBPFLAG flag = TBPF_NORMAL; @@ -96,45 +68,45 @@ bool TaskbarSeven::setStatus(TBHandle handle, break; } - ITaskbarList3* pto = taskBarHandles[handle]; - if (pto) + 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)) { - HRESULT hr = pto->SetProgressState(static_cast<HWND>(hwnd), //[in] HWND hwnd, - flag); //[in] TBPFLAG tbpFlags - if (FAILED(hr)) - { - lastErrorMessage = generateErrorMsg(L"Error calling \"SetProgressState\".", hr); - return false; - } + lastErrorMessage = generateErrorMsg(L"Error calling \"SetProgressState\".", hr); + return false; } + return true; } -bool TaskbarSeven::setProgress(TBHandle handle, - void* hwnd, //HWND: window assciated to the taskbar icon +bool tbseven::setProgress(void* hwnd, //HWND: window assciated to the taskbar icon size_t current, size_t total) { - ITaskbarList3* pto = taskBarHandles[handle]; - - if (pto) + 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)) { - HRESULT hr = pto->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; - } + lastErrorMessage = generateErrorMsg(L"Error calling \"SetProgressValue\".", hr); + return false; } + return true; } -void TaskbarSeven::getLastError(wchar_t* errorMessage, size_t errorBufferLen) +void tbseven::getLastError(wchar_t* errorMessage, size_t errorBufferLen) { writeString(lastErrorMessage, errorMessage, errorBufferLen); } |