Updater/UI: ITaskbarlist3 handling improvements.

* Properly error-check the interface querying and instance creation.
* Call HrInit() as required when getting the instance.
This commit is contained in:
Pierre Bourdon 2018-11-22 02:34:26 +01:00
parent 1805f51d79
commit c9d5ac3e9a
1 changed files with 22 additions and 4 deletions

View File

@ -47,7 +47,16 @@ bool Init()
if (!window_handle)
return false;
CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&taskbar_list));
if (FAILED(CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&taskbar_list))))
{
taskbar_list = nullptr;
}
if (taskbar_list && FAILED(taskbar_list->HrInit()))
{
taskbar_list->Release();
taskbar_list = nullptr;
}
label_handle = CreateWindow(L"STATIC", NULL, WS_VISIBLE | WS_CHILD, 5, 5, 500, 25, window_handle,
nullptr, nullptr, 0);
@ -93,7 +102,10 @@ void SetTotalMarquee(bool marquee)
SetWindowLong(total_progressbar_handle, GWL_STYLE,
PROGRESSBAR_FLAGS | (marquee ? PBS_MARQUEE : 0));
SendMessage(total_progressbar_handle, PBM_SETMARQUEE, marquee, 0);
taskbar_list->SetProgressState(window_handle, marquee ? TBPF_INDETERMINATE : TBPF_NORMAL);
if (taskbar_list)
{
taskbar_list->SetProgressState(window_handle, marquee ? TBPF_INDETERMINATE : TBPF_NORMAL);
}
}
void ResetTotalProgress()
@ -106,7 +118,10 @@ void SetTotalProgress(int current, int total)
{
SendMessage(total_progressbar_handle, PBM_SETRANGE32, 0, total);
SendMessage(total_progressbar_handle, PBM_SETPOS, current, 0);
taskbar_list->SetProgressValue(window_handle, current, total);
if (taskbar_list)
{
taskbar_list->SetProgressValue(window_handle, current, total);
}
}
void SetCurrentMarquee(bool marquee)
@ -130,7 +145,10 @@ void Error(const std::string& text)
(L"A fatal error occured and the updater cannot continue:\n " + wide_text).c_str(),
L"Error", MB_ICONERROR);
taskbar_list->SetProgressState(window_handle, TBPF_ERROR);
if (taskbar_list)
{
taskbar_list->SetProgressState(window_handle, TBPF_ERROR);
}
}
void SetCurrentProgress(int current, int total)