Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » How to set progress in taskbar button
How to set progress in taskbar button [message #49235] |
Wed, 10 January 2018 08:48 |
|
koldo
Messages: 3372 Registered: August 2008
|
Senior Veteran |
|
|
This code snippet displays a progress indicator in the Windows 7-10 taskbar button.
It has just 3 functions: Init(), SetValue(val, max) and End().
#if defined(PLATFORM_WIN32)
#include <winnls.h>
#include <winnetwk.h>
#define Ptr Ptr_
#define CY tagCY
#include <wincon.h>
#include <shlobj.h>
#undef CY
#undef Ptr
class TaskbarProgress {
public:
TaskbarProgress() : m_hWnd(0) {}
void Init() {
m_hWnd = ::GetActiveWindow();
HRESULT hres;
hres = CoInitialize(NULL);
hres = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_ALL, IID_ITaskbarList3, (void**)&m_pTaskBarlist);
m_pTaskBarlist->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
}
void SetValue(int val, int max) {
ASSERT(val >= 0 && val <= max);
if (!m_hWnd)
return;
m_pTaskBarlist->SetProgressValue(m_hWnd, val, max);
}
void End() {
if (!m_hWnd)
return;
m_pTaskBarlist->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
m_pTaskBarlist->Release();
m_hWnd = 0;
}
private:
ITaskbarList3* m_pTaskBarlist;
HWND m_hWnd;
};
#endif
-
Attachment: index.jpg
(Size: 12.82KB, Downloaded 432 times)
Best regards
IƱaki
|
|
|
Goto Forum:
Current Time: Sun Jun 16 16:35:24 CEST 2024
Total time taken to generate the page: 0.02567 seconds
|