499 lines
16 KiB
C#
499 lines
16 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: CarotDAV.TaskbarManager
|
|
// Assembly: CarotDAV, Version=1.13.2.18337, Culture=neutral, PublicKeyToken=null
|
|
// MVID: C31F2651-A4A8-4D09-916A-8C6106F5E7C8
|
|
// Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\CarotDAV.exe
|
|
|
|
using Microsoft.VisualBasic.CompilerServices;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace CarotDAV
|
|
{
|
|
public class TaskbarManager
|
|
{
|
|
private static int pTaskbarButtonCreatedMessage = -1;
|
|
private static TaskbarManager.ITaskbarList4 pTaskbarList4;
|
|
private static TaskbarManager.PropertyKey PKEY_Title;
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
private static extern int RegisterWindowMessage([MarshalAs(UnmanagedType.LPWStr)] string lpString);
|
|
|
|
[DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
private static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);
|
|
|
|
[DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
private static extern void SHAddToRecentDocs(TaskbarManager.SHARD uflag, [In] ref TaskbarManager.SHARDAPPIDINFOLINK pv);
|
|
|
|
static TaskbarManager()
|
|
{
|
|
try
|
|
{
|
|
TaskbarManager.pTaskbarList4 = Activator.CreateInstance(System.Type.GetTypeFromCLSID(new Guid("56FDF344-FD6D-11d0-958A-006097C9A090"))) as TaskbarManager.ITaskbarList4;
|
|
if (TaskbarManager.pTaskbarList4 != null)
|
|
TaskbarManager.pTaskbarList4.HrInit();
|
|
}
|
|
catch (COMException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
TaskbarManager.pTaskbarList4 = (TaskbarManager.ITaskbarList4) null;
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
catch (NotImplementedException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
TaskbarManager.pTaskbarList4 = (TaskbarManager.ITaskbarList4) null;
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
TaskbarManager.PKEY_Title = new TaskbarManager.PropertyKey();
|
|
TaskbarManager.PKEY_Title.fmtid = new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9");
|
|
TaskbarManager.PKEY_Title.pid = 2;
|
|
}
|
|
|
|
public static int TaskbarButtonCreatedMessage
|
|
{
|
|
get
|
|
{
|
|
return TaskbarManager.pTaskbarButtonCreatedMessage;
|
|
}
|
|
}
|
|
|
|
public static void RegisterTaskbarMessage()
|
|
{
|
|
try
|
|
{
|
|
if (TaskbarManager.pTaskbarButtonCreatedMessage != -1)
|
|
return;
|
|
TaskbarManager.pTaskbarButtonCreatedMessage = TaskbarManager.RegisterWindowMessage("TaskbarButtonCreated");
|
|
}
|
|
catch (DllNotFoundException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
catch (EntryPointNotFoundException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
}
|
|
|
|
public static void SetAppUserModelID(string AppID)
|
|
{
|
|
try
|
|
{
|
|
TaskbarManager.SetCurrentProcessExplicitAppUserModelID(AppID);
|
|
}
|
|
catch (DllNotFoundException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
catch (EntryPointNotFoundException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
}
|
|
|
|
private static TaskbarManager.IShellLinkW CreateShellLink(string apppath, string arguments, string title, string tooltip, string iconpath, int iconindex)
|
|
{
|
|
try
|
|
{
|
|
TaskbarManager.IShellLinkW instance = Activator.CreateInstance(System.Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"))) as TaskbarManager.IShellLinkW;
|
|
if (instance == null)
|
|
return (TaskbarManager.IShellLinkW) null;
|
|
TaskbarManager.IPropertyStore propertyStore = instance as TaskbarManager.IPropertyStore;
|
|
if (propertyStore == null)
|
|
return (TaskbarManager.IShellLinkW) null;
|
|
instance.SetPath(apppath);
|
|
if (arguments != null)
|
|
instance.SetArguments(arguments);
|
|
if (iconpath != null)
|
|
instance.SetIconLocation(iconpath, iconindex);
|
|
if (tooltip != null)
|
|
instance.SetDescription(tooltip);
|
|
propertyStore.SetValue(ref TaskbarManager.PKEY_Title, ref new TaskbarManager.PropVariant()
|
|
{
|
|
_ptr = Marshal.StringToCoTaskMemUni(title),
|
|
_valueType = VarEnum.VT_LPWSTR
|
|
});
|
|
propertyStore.Commit();
|
|
return instance;
|
|
}
|
|
catch (COMException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
catch (NotImplementedException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
return (TaskbarManager.IShellLinkW) null;
|
|
}
|
|
|
|
public static void AddToRecent(string appid, string apppath, string arguments, string title, string tooltip, string iconpath, int iconindex)
|
|
{
|
|
if (!TaskbarManager.IsSupportJumpList)
|
|
return;
|
|
TaskbarManager.IShellLinkW shellLink = TaskbarManager.CreateShellLink(apppath, arguments, title, tooltip, iconpath, iconindex);
|
|
if (shellLink == null)
|
|
return;
|
|
TaskbarManager.SHARDAPPIDINFOLINK pv;
|
|
pv.psl = shellLink;
|
|
pv.pszAppID = appid;
|
|
TaskbarManager.SHAddToRecentDocs(TaskbarManager.SHARD.SHARD_APPIDINFOLINK, ref pv);
|
|
}
|
|
|
|
public static void SetJumpListKnownCategory(string appid, bool frequent)
|
|
{
|
|
if (!TaskbarManager.IsSupportJumpList)
|
|
return;
|
|
try
|
|
{
|
|
TaskbarManager.ICustomDestinationList instance = Activator.CreateInstance(System.Type.GetTypeFromCLSID(new Guid("77F10CF0-3DB5-4966-B520-B7C54FD35ED6"))) as TaskbarManager.ICustomDestinationList;
|
|
if (instance == null)
|
|
return;
|
|
Guid riid = new Guid("92CA9DCD-5622-4BBA-A805-5E9F541BD8C9");
|
|
object ppvObject = (object) null;
|
|
instance.SetAppID(appid);
|
|
uint cMaxSlots;
|
|
instance.BeginList(out cMaxSlots, ref riid, out ppvObject);
|
|
if (frequent)
|
|
instance.AppendKnownCategory(TaskbarManager.KnownDestinationCategory.Frequent);
|
|
else
|
|
instance.AppendKnownCategory(TaskbarManager.KnownDestinationCategory.Recent);
|
|
instance.CommitList();
|
|
}
|
|
catch (COMException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
catch (NotImplementedException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
}
|
|
|
|
public static void ClearJumpList(string appid)
|
|
{
|
|
if (!TaskbarManager.IsSupportJumpList)
|
|
return;
|
|
try
|
|
{
|
|
TaskbarManager.IApplicationDestination instance = Activator.CreateInstance(System.Type.GetTypeFromCLSID(new Guid("86C14003-4D6B-4EF3-A7B4-0506663B2E68"))) as TaskbarManager.IApplicationDestination;
|
|
if (instance == null)
|
|
return;
|
|
instance.SetAppID(appid);
|
|
instance.RemoveAllDestinations();
|
|
}
|
|
catch (COMException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
catch (NotImplementedException ex)
|
|
{
|
|
ProjectData.SetProjectError((Exception) ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
}
|
|
|
|
public static void SetProgressState(Control control, TaskbarManager.TaskbarProgressBarStatus tbpFlags)
|
|
{
|
|
if (!TaskbarManager.IsSupportJumpList)
|
|
return;
|
|
try
|
|
{
|
|
TaskbarManager.pTaskbarList4.SetProgressState(control.Handle, tbpFlags);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ProjectData.SetProjectError(ex);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
}
|
|
|
|
public static void SetProgressValue(Control control, ulong ullCompleted, ulong ullTotal)
|
|
{
|
|
if (!TaskbarManager.IsSupportJumpList)
|
|
return;
|
|
TaskbarManager.pTaskbarList4.SetProgressValue(control.Handle, ullCompleted, ullTotal);
|
|
}
|
|
|
|
public static bool IsSupportJumpList
|
|
{
|
|
get
|
|
{
|
|
return TaskbarManager.pTaskbarList4 != null;
|
|
}
|
|
}
|
|
|
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
[Guid("C43DC798-95D1-4BEA-9030-BB99E2983A1A")]
|
|
[ComImport]
|
|
private interface ITaskbarList4
|
|
{
|
|
void HrInit();
|
|
|
|
void AddTab(IntPtr hwnd);
|
|
|
|
void DeleteTab(IntPtr hwnd);
|
|
|
|
void ActivateTab(IntPtr hwnd);
|
|
|
|
void SetActiveAlt(IntPtr hwnd);
|
|
|
|
void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
|
|
|
|
void SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal);
|
|
|
|
void SetProgressState(IntPtr hwnd, TaskbarManager.TaskbarProgressBarStatus tbpFlags);
|
|
|
|
void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);
|
|
|
|
void UnregisterTab(IntPtr hwndTab);
|
|
|
|
void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore);
|
|
|
|
void SetTabActive(IntPtr hwndTab, IntPtr hwndInsertBefore, uint dwReserved);
|
|
|
|
void ThumbBarAddButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray)] TaskbarManager.ThumbButton[] pButtons);
|
|
|
|
void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl);
|
|
|
|
void ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray)] TaskbarManager.ThumbButton[] pButtons);
|
|
|
|
void SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string pszDescription);
|
|
|
|
void SetThumbnailClip(IntPtr hwnd, IntPtr prcClip);
|
|
|
|
void SetThumbnailTooltip(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszTip);
|
|
|
|
void SetTabProperties(IntPtr hwndTab, TaskbarManager.SetTabPropertiesOption stpFlags);
|
|
}
|
|
|
|
public enum TaskbarProgressBarStatus
|
|
{
|
|
NoProgress = 0,
|
|
Indeterminate = 1,
|
|
Normal = 2,
|
|
Error = 4,
|
|
Paused = 8,
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
|
public struct ThumbButton
|
|
{
|
|
internal const int Clicked = 6144;
|
|
[MarshalAs(UnmanagedType.U4)]
|
|
internal TaskbarManager.ThumbButtonMask Mask;
|
|
internal uint Id;
|
|
internal uint Bitmap;
|
|
internal IntPtr Icon;
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
|
internal string Tip;
|
|
[MarshalAs(UnmanagedType.U4)]
|
|
internal TaskbarManager.ThumbButtonOptions Flags;
|
|
}
|
|
|
|
public enum ThumbButtonMask
|
|
{
|
|
Bitmap = 1,
|
|
Icon = 2,
|
|
Tooltip = 4,
|
|
THB_FLAGS = 8,
|
|
}
|
|
|
|
[Flags]
|
|
public enum ThumbButtonOptions
|
|
{
|
|
Disabled = 1,
|
|
DismissOnClick = 2,
|
|
Enabled = 0,
|
|
Hidden = 8,
|
|
NoBackground = 4,
|
|
NonInteractive = 16,
|
|
}
|
|
|
|
public enum SetTabPropertiesOption
|
|
{
|
|
None = 0,
|
|
UseAppThumbnailAlways = 1,
|
|
UseAppThumbnailWhenActive = 2,
|
|
UseAppPeekAlways = 4,
|
|
UseAppPeekWhenActive = 8,
|
|
}
|
|
|
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
[Guid("6332DEBF-87B5-4670-90C0-5E57B408A49E")]
|
|
[ComImport]
|
|
private interface ICustomDestinationList
|
|
{
|
|
void SetAppID([MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
|
|
|
|
void BeginList(out uint cMaxSlots, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject);
|
|
|
|
void AppendCategory([MarshalAs(UnmanagedType.LPWStr)] string pszCategory, [MarshalAs(UnmanagedType.Interface)] TaskbarManager.IObjectArray poa);
|
|
|
|
void AppendKnownCategory([MarshalAs(UnmanagedType.I4)] TaskbarManager.KnownDestinationCategory category);
|
|
|
|
void AddUserTasks([MarshalAs(UnmanagedType.Interface)] TaskbarManager.IObjectArray poa);
|
|
|
|
void CommitList();
|
|
|
|
void GetRemovedDestinations(ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject);
|
|
|
|
void DeleteList([MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
|
|
|
|
void AbortList();
|
|
}
|
|
|
|
[Guid("92CA9DCD-5622-4BBA-A805-5E9F541BD8C9")]
|
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
[ComImport]
|
|
private interface IObjectArray
|
|
{
|
|
void GetCount(out uint cObjects);
|
|
|
|
void GetAt(uint iIndex, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject);
|
|
}
|
|
|
|
public enum KnownDestinationCategory
|
|
{
|
|
Frequent = 1,
|
|
Recent = 2,
|
|
}
|
|
|
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
[Guid("000214F9-0000-0000-C000-000000000046")]
|
|
[ComImport]
|
|
private interface IShellLinkW
|
|
{
|
|
void GetPath([MarshalAs(UnmanagedType.LPWStr), Out] StringBuilder pszFile, int cchMaxPath, IntPtr pfd, uint fFlags);
|
|
|
|
void GetIDList(out IntPtr ppidl);
|
|
|
|
void SetIDList(IntPtr pidl);
|
|
|
|
void GetDescription([MarshalAs(UnmanagedType.LPWStr), Out] StringBuilder pszFile, int cchMaxName);
|
|
|
|
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
|
|
|
|
void GetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr), Out] StringBuilder pszDir, int cchMaxPath);
|
|
|
|
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
|
|
|
|
void GetArguments([MarshalAs(UnmanagedType.LPWStr), Out] StringBuilder pszArgs, int cchMaxPath);
|
|
|
|
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
|
|
|
|
void GetHotKey(out short wHotKey);
|
|
|
|
void SetHotKey(short wHotKey);
|
|
|
|
void GetShowCmd(out uint iShowCmd);
|
|
|
|
void SetShowCmd(uint iShowCmd);
|
|
|
|
void GetIconLocation([MarshalAs(UnmanagedType.LPWStr)] out StringBuilder pszIconPath, int cchIconPath, out int iIcon);
|
|
|
|
void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
|
|
|
|
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved);
|
|
|
|
void Resolve(IntPtr hwnd, uint fFlags);
|
|
|
|
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
|
|
}
|
|
|
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
[Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99")]
|
|
[ComImport]
|
|
private interface IPropertyStore
|
|
{
|
|
void GetCount(out uint propertyCount);
|
|
|
|
void GetAt([In] uint propertyIndex, out TaskbarManager.PropertyKey key);
|
|
|
|
void GetValue([In] ref TaskbarManager.PropertyKey key, out TaskbarManager.PropVariant pv);
|
|
|
|
void SetValue([In] ref TaskbarManager.PropertyKey key, [In] ref TaskbarManager.PropVariant pv);
|
|
|
|
void Commit();
|
|
}
|
|
|
|
private struct PropertyKey
|
|
{
|
|
public Guid fmtid;
|
|
public int pid;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Explicit)]
|
|
private struct PropVariant
|
|
{
|
|
[FieldOffset(0)]
|
|
public VarEnum _valueType;
|
|
[FieldOffset(8)]
|
|
public IntPtr _ptr;
|
|
[FieldOffset(8)]
|
|
public sbyte _sbyte;
|
|
[FieldOffset(8)]
|
|
public short _short;
|
|
[FieldOffset(8)]
|
|
public int _int32;
|
|
[FieldOffset(8)]
|
|
public long _long;
|
|
[FieldOffset(8)]
|
|
public byte _byte;
|
|
[FieldOffset(8)]
|
|
public ushort _ushort;
|
|
[FieldOffset(8)]
|
|
public uint _uint32;
|
|
[FieldOffset(8)]
|
|
public ulong _ulong;
|
|
[FieldOffset(8)]
|
|
public double _double;
|
|
[FieldOffset(8)]
|
|
public float _float;
|
|
}
|
|
|
|
private struct SHARDAPPIDINFOLINK
|
|
{
|
|
public TaskbarManager.IShellLinkW psl;
|
|
[MarshalAs(UnmanagedType.LPWStr)]
|
|
public string pszAppID;
|
|
}
|
|
|
|
private enum SHARD
|
|
{
|
|
SHARD_PIDL = 1,
|
|
SHARD_PATHA = 2,
|
|
SHARD_PATHW = 3,
|
|
SHARD_APPIDINFO = 4,
|
|
SHARD_APPIDINFOIDLIST = 5,
|
|
SHARD_LINK = 6,
|
|
SHARD_APPIDINFOLINK = 7,
|
|
SHARD_SHELLITEM = 8,
|
|
}
|
|
|
|
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
[Guid("12337D35-94C6-48A0-BCE7-6A9C69D4D600")]
|
|
[ComImport]
|
|
private interface IApplicationDestination
|
|
{
|
|
void SetAppID([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
|
|
|
|
void RemoveDestination(object punk);
|
|
|
|
void RemoveAllDestinations();
|
|
}
|
|
}
|
|
}
|