Created
October 16, 2017 04:59
-
-
Save Superbelko/277d86a17d497eae85a7f1788bfd83b4 to your computer and use it in GitHub Desktop.
ITaskbarList3 usage example in D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Basic ITaskbarList3 example in D | |
* | |
* ported from C# version | |
* https://stackoverflow.com/questions/1295890/windows-7-progress-bar-in-taskbar-in-c/17243993 | |
*/ | |
import std.stdio; | |
import core.sys.windows.windows; | |
import core.sys.windows.com; | |
import core.sys.windows.unknwn; | |
static const IID IID_ITaskbarList3 = {0xea1afb91, 0x9e28, 0x4b86, [0x90, 0xe9, 0x9e, 0x9f, 0x8a, 0x5e, 0xef, 0xaf]}; | |
// not sure about name or actual GUID | |
static const IID CLSID_ITaskbarList3 = {0x56fdf344, 0xfd6d, 0x11d0, [0x95, 0x8a, 0x00, 0x60, 0x97, 0xc9, 0xa0, 0x90]}; | |
public enum TaskbarStates | |
{ | |
NoProgress = 0, | |
Indeterminate = 0x1, | |
Normal = 0x2, | |
Error = 0x4, | |
Paused = 0x8 | |
} | |
interface ITaskbarList3 : IUnknown | |
{ | |
// ITaskbarList | |
void HrInit(); | |
void AddTab(HWND hwnd); | |
void DeleteTab(HWND hwnd); | |
void ActivateTab(HWND hwnd); | |
void SetActiveAlt(HWND hwnd); | |
// ITaskbarList2 | |
void MarkFullscreenWindow(HWND hwnd, bool fFullscreen); | |
// ITaskbarList3 | |
void SetProgressValue(HWND hwnd, ulong ullCompleted, ulong ullTotal); | |
void SetProgressState(HWND hwnd, TaskbarStates state); | |
} | |
// simple example | |
pragma(lib, "ole32.lib"); // for COM stuff | |
void main() | |
{ | |
ITaskbarList3 taskbar; | |
CoInitialize(null); | |
scope(exit) CoUninitialize(); | |
// scope exit order is important here, can also release manually before CoUninitialize | |
scope(exit) if(taskbar) { taskbar.Release(); taskbar = null; } | |
HRESULT hr = CoCreateInstance(&CLSID_ITaskbarList3, null, CLSCTX_INPROC_SERVER, &IID_ITaskbarList3, cast(void**)&taskbar); | |
if(hr!=S_OK) | |
{ | |
switch(hr) | |
{ | |
case REGDB_E_CLASSNOTREG: | |
writeln("err: not reg"); break; | |
case CLASS_E_NOAGGREGATION: | |
writeln("err: class no aggregation"); break; | |
/* not present in core.sys.windows.* | |
case CLASS_E_NOINTERFACE: | |
writeln("err. class no aggregation"); break; | |
case CLASS_E_POINTER: | |
writeln("err. class no aggregation"); break; | |
*/ | |
default: | |
writeln("unexpected error: ", hr); | |
} | |
} | |
auto hwnd = GetConsoleWindow(); | |
if (!taskbar || hwnd is null) | |
{ | |
writeln("err: no taskbar or window handle"); | |
return; | |
} | |
// blinking indicator | |
taskbar.SetProgressState(hwnd, TaskbarStates.Indeterminate); | |
writeln("press enter to set normal state"); | |
readln(); | |
// normal fill indicator | |
taskbar.SetProgressState(hwnd, TaskbarStates.Normal); | |
writeln("press enter to increment progress"); | |
foreach(i; 0..10) | |
{ | |
taskbar.SetProgressValue(hwnd, i, 10); | |
readln(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment