Files
Labview-Program/Windows 7 Taskbar/C# Source Code/Windows7Taskbar/Win7Taskbar.cs
chanweehewsonos 8180f4ff4f Initial
2025-09-10 13:59:40 +08:00

211 lines
6.0 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace Windows7Taskbar
{
#region Interop ITaskbarList3
internal enum TBPFLAG
{
TBPF_NOPROGRESS = 0,
TBPF_INDETERMINATE = 0x1,
TBPF_NORMAL = 0x2,
TBPF_ERROR = 0x4,
TBPF_PAUSED = 0x8
}
internal enum TBATFLAG
{
TBATF_USEMDITHUMBNAIL = 0x1,
TBATF_USEMDILIVEPREVIEW = 0x2
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal struct THUMBBUTTON
{
[MarshalAs(UnmanagedType.U4)]
public THBMASK dwMask;
public uint iId;
public uint iBitmap;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szTip;
[MarshalAs(UnmanagedType.U4)]
public THBFLAGS dwFlags;
}
[StructLayout(LayoutKind.Sequential)]
internal struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}
internal enum THBMASK
{
THB_BITMAP = 0x1,
THB_ICON = 0x2,
THB_TOOLTIP = 0x4,
THB_FLAGS = 0x8
}
internal enum THBFLAGS
{
THBF_ENABLED = 0,
THBF_DISABLED = 0x1,
THBF_DISMISSONCLICK = 0x2,
THBF_NOBACKGROUND = 0x4,
THBF_HIDDEN = 0x8
}
[ComImportAttribute()]
[GuidAttribute("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
internal 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
void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
void SetProgressState(IntPtr hwnd, TBPFLAG tbpFlags);
void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);
void UnregisterTab(IntPtr hwndTab);
void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore);
void SetTabActive(IntPtr hwndTab, IntPtr hwndMDI, TBATFLAG tbatFlags);
void ThumbBarAddButtons(
IntPtr hwnd,
uint cButtons,
[MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons);
void ThumbBarUpdateButtons(
IntPtr hwnd,
uint cButtons,
[MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons);
void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl);
void SetOverlayIcon(
IntPtr hwnd,
IntPtr hIcon,
[MarshalAs(UnmanagedType.LPWStr)] string pszDescription);
void SetThumbnailTooltip(
IntPtr hwnd,
[MarshalAs(UnmanagedType.LPWStr)] string pszTip);
void SetThumbnailClip(
IntPtr hwnd,
/*[MarshalAs(UnmanagedType.LPStruct)]*/ ref RECT prcClip);
}
[GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComImportAttribute()]
internal class CTaskbarList { }
#endregion
public static class Windows7Taskbar
{
#region Infrastructure
private static ITaskbarList3 _taskbarList;
internal static ITaskbarList3 TaskbarList
{
get
{
if (_taskbarList == null)
{
lock (typeof(Windows7Taskbar))
{
if (_taskbarList == null)
{
_taskbarList = (ITaskbarList3)new CTaskbarList();
_taskbarList.HrInit();
}
}
}
return _taskbarList;
}
}
#endregion
#region Taskbar Progress Bar
/// <summary>
/// Represents the thumbnail progress bar state.
/// </summary>
public enum ThumbnailProgressState
{
/// <summary>
/// No progress is displayed.
/// </summary>
NoProgress = 0,
/// <summary>
/// The progress is indeterminate (marquee).
/// </summary>
Indeterminate = 0x1,
/// <summary>
/// Normal progress is displayed.
/// </summary>
Normal = 0x2,
/// <summary>
/// An error occurred (red).
/// </summary>
Error = 0x4,
/// <summary>
/// The operation is paused (yellow).
/// </summary>
Paused = 0x8
}
/// <summary>
/// Sets the progress state of the specified window's
/// taskbar button.
/// </summary>
/// <param name="hwnd">The window handle.</param>
/// <param name="state">The progress state.</param>
public static void SetProgressState(IntPtr hwnd,
ThumbnailProgressState state)
{
TaskbarList.SetProgressState(hwnd, (TBPFLAG)state);
}
/// <summary>
/// Sets the progress value of the specified window's
/// taskbar button.
/// </summary>
/// <param name="hwnd">The window handle.</param>
/// <param name="current">The current value.</param>
/// <param name="maximum">The maximum value.</param>
public static void SetProgressValue(IntPtr hwnd,
ulong current, ulong maximum)
{
TaskbarList.SetProgressValue(hwnd, current, maximum);
}
#endregion
}
}