2016-10-31 14:49:08 +00:00
|
|
|
|
#region ======================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-10-06 14:30:24 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
2016-10-31 14:49:08 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2016-10-06 14:30:24 +00:00
|
|
|
|
namespace mxd.GZDBUpdater
|
|
|
|
|
{
|
|
|
|
|
// http://stackoverflow.com/questions/1295890/windows-7-progress-bar-in-taskbar-in-c
|
|
|
|
|
public static class TaskbarProgress
|
|
|
|
|
{
|
2016-10-31 14:49:08 +00:00
|
|
|
|
#region ======================== TaskbarInstance
|
|
|
|
|
|
2016-10-06 14:30:24 +00:00
|
|
|
|
public enum TaskbarStates
|
|
|
|
|
{
|
|
|
|
|
NoProgress = 0,
|
|
|
|
|
Indeterminate = 0x1,
|
|
|
|
|
Normal = 0x2,
|
|
|
|
|
Error = 0x4,
|
|
|
|
|
Paused = 0x8
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 14:49:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ComImportAttribute]
|
2016-10-06 14:30:24 +00:00
|
|
|
|
[GuidAttribute("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
|
|
|
|
|
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
|
|
|
|
|
private interface ITaskbarList3
|
|
|
|
|
{
|
|
|
|
|
// ITaskbarList
|
|
|
|
|
[PreserveSig]
|
|
|
|
|
void HrInit();
|
|
|
|
|
[PreserveSig]
|
|
|
|
|
void AddTab(IntPtr hwnd);
|
|
|
|
|
[PreserveSig]
|
|
|
|
|
void DeleteTab(IntPtr hwnd);
|
|
|
|
|
[PreserveSig]
|
|
|
|
|
void ActivateTab(IntPtr hwnd);
|
|
|
|
|
[PreserveSig]
|
|
|
|
|
void SetActiveAlt(IntPtr hwnd);
|
|
|
|
|
|
|
|
|
|
// ITaskbarList2
|
|
|
|
|
[PreserveSig]
|
|
|
|
|
void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
|
|
|
|
|
|
|
|
|
|
// ITaskbarList3
|
|
|
|
|
[PreserveSig]
|
|
|
|
|
void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
|
|
|
|
|
[PreserveSig]
|
|
|
|
|
void SetProgressState(IntPtr hwnd, TaskbarStates state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")]
|
|
|
|
|
[ClassInterfaceAttribute(ClassInterfaceType.None)]
|
2016-10-31 14:49:08 +00:00
|
|
|
|
[ComImportAttribute]
|
2016-10-06 14:30:24 +00:00
|
|
|
|
private class TaskbarInstance
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 14:49:08 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ======================== Variables
|
|
|
|
|
|
|
|
|
|
private static ITaskbarList3 taskbarinstance;
|
|
|
|
|
private static bool taskbarsupported; //mxd. Environment.OSVersion.Version won't save us here...
|
2016-10-31 18:52:29 +00:00
|
|
|
|
private static bool checkperformed;
|
2016-10-31 14:49:08 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ======================== Methods
|
2016-10-06 14:30:24 +00:00
|
|
|
|
|
|
|
|
|
public static void SetState(IntPtr windowHandle, TaskbarStates taskbarState)
|
|
|
|
|
{
|
2016-10-31 14:49:08 +00:00
|
|
|
|
if(TaskBarSupported()) taskbarinstance.SetProgressState(windowHandle, taskbarState);
|
2016-10-06 14:30:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax)
|
|
|
|
|
{
|
2016-10-31 14:49:08 +00:00
|
|
|
|
if(TaskBarSupported()) taskbarinstance.SetProgressValue(windowHandle, (ulong)progressValue, (ulong)progressMax);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//mxd
|
|
|
|
|
private static bool TaskBarSupported()
|
|
|
|
|
{
|
2016-10-31 18:52:29 +00:00
|
|
|
|
if(!checkperformed)
|
2016-10-31 14:49:08 +00:00
|
|
|
|
{
|
2016-10-31 18:52:29 +00:00
|
|
|
|
checkperformed = true;
|
2016-10-31 14:49:08 +00:00
|
|
|
|
taskbarsupported = true;
|
|
|
|
|
try { taskbarinstance = (ITaskbarList3)new TaskbarInstance(); }
|
|
|
|
|
catch { taskbarsupported = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return taskbarsupported;
|
2016-10-06 14:30:24 +00:00
|
|
|
|
}
|
2016-10-31 14:49:08 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2016-10-06 14:30:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|