summaryrefslogtreecommitdiff
path: root/shared/Taskbar_Seven/taskbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'shared/Taskbar_Seven/taskbar.cpp')
-rw-r--r--shared/Taskbar_Seven/taskbar.cpp112
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);
}
bgstack15