diff --git a/src/HandyControl.sln b/src/HandyControl.sln index 36dc8888..39a603b4 100644 --- a/src/HandyControl.sln +++ b/src/HandyControl.sln @@ -23,11 +23,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HandyControlDemo_Net_40", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HandyControlDemo_Code", "Shared\HandyControlDemo_Code\HandyControlDemo_Code.csproj", "{D8A4748C-0500-4F63-BC47-3506658C68F7}" EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.Windows.Shell", "Shared\Microsoft.Windows.Shell\Microsoft.Windows.Shell.shproj", "{BBE51380-8B21-49FF-9CFC-B29447A40999}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution Shared\HandyControl_Shared\HandyControl_Shared.projitems*{32204503-2ef0-4681-ae13-aa1feb6c658a}*SharedItemsImports = 5 + Shared\Microsoft.Windows.Shell\Microsoft.Windows.Shell.projitems*{32204503-2ef0-4681-ae13-aa1feb6c658a}*SharedItemsImports = 5 Shared\HandyControlDemo_Shared\HandyControlDemo_Shared.projitems*{9a7b52e6-94bb-4e7e-bb6a-7cf6761b79a7}*SharedItemsImports = 5 Shared\HandyControl_Shared\HandyControl_Shared.projitems*{aac11083-faca-405d-9197-5c1212d65656}*SharedItemsImports = 13 + Shared\Microsoft.Windows.Shell\Microsoft.Windows.Shell.projitems*{bbe51380-8b21-49ff-9cfc-b29447a40999}*SharedItemsImports = 13 Shared\HandyControlDemo_Shared\HandyControlDemo_Shared.projitems*{c4694269-c9b8-45d5-87f8-d0088c532510}*SharedItemsImports = 13 Shared\HandyControlDemo_Shared\HandyControlDemo_Shared.projitems*{d8ae88f8-c36b-4d10-a7f9-22ffcfba5231}*SharedItemsImports = 5 Shared\HandyControl_Shared\HandyControl_Shared.projitems*{dc966e3d-bcff-4652-98cf-070e5494749a}*SharedItemsImports = 5 @@ -83,6 +87,7 @@ Global {32204503-2EF0-4681-AE13-AA1FEB6C658A} = {35E3F9C0-8924-4536-BE09-F3761FDBF066} {D8AE88F8-C36B-4D10-A7F9-22FFCFBA5231} = {35E3F9C0-8924-4536-BE09-F3761FDBF066} {D8A4748C-0500-4F63-BC47-3506658C68F7} = {0938270D-E9F0-489B-AF9E-5C5AD7C69897} + {BBE51380-8B21-49FF-9CFC-B29447A40999} = {0938270D-E9F0-489B-AF9E-5C5AD7C69897} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D4636382-1A18-4079-A3E7-054DD970F179} diff --git a/src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj b/src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj index fe610463..9b433da3 100644 --- a/src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj +++ b/src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj @@ -13,11 +13,6 @@ bin\$(Configuration)\$(TargetFramework)\HandyControl.xml - - - 3.0.1 - - Properties\Langs\Lang.Designer.cs @@ -74,6 +69,7 @@ + Resources\dropper.cur diff --git a/src/Net_40/HandyControl_Net_40/Themes/Styles/MessageBox.xaml b/src/Net_40/HandyControl_Net_40/Themes/Styles/MessageBox.xaml index 35de3ab3..a907896e 100644 --- a/src/Net_40/HandyControl_Net_40/Themes/Styles/MessageBox.xaml +++ b/src/Net_40/HandyControl_Net_40/Themes/Styles/MessageBox.xaml @@ -1,8 +1,8 @@  @@ -104,4 +104,4 @@ - \ No newline at end of file + diff --git a/src/Net_40/HandyControl_Net_40/Themes/Styles/Window.xaml b/src/Net_40/HandyControl_Net_40/Themes/Styles/Window.xaml index ee60d042..4f5346e3 100644 --- a/src/Net_40/HandyControl_Net_40/Themes/Styles/Window.xaml +++ b/src/Net_40/HandyControl_Net_40/Themes/Styles/Window.xaml @@ -1,8 +1,8 @@ - @@ -241,4 +241,4 @@ - \ No newline at end of file + diff --git a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml index 040196e7..d1b8d608 100644 --- a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml +++ b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml @@ -1,4 +1,4 @@ - + diff --git a/src/Shared/HandyControl_Shared/Properties/AssemblyInfo.cs b/src/Shared/HandyControl_Shared/Properties/AssemblyInfo.cs index b4e566f8..a74a8f4b 100644 --- a/src/Shared/HandyControl_Shared/Properties/AssemblyInfo.cs +++ b/src/Shared/HandyControl_Shared/Properties/AssemblyInfo.cs @@ -12,4 +12,5 @@ [assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Data")] [assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Properties.Langs")] [assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "HandyControl.Themes")] +[assembly: XmlnsDefinition("https://handyorg.github.io/handycontrol", "Microsoft.Windows.Shell")] [assembly: XmlnsPrefix("https://handyorg.github.io/handycontrol", "hc")] diff --git a/src/Shared/Microsoft.Windows.Shell/JumpItem.cs b/src/Shared/Microsoft.Windows.Shell/JumpItem.cs new file mode 100644 index 00000000..2733344e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/JumpItem.cs @@ -0,0 +1,13 @@ +using System; + +namespace Microsoft.Windows.Shell +{ + public abstract class JumpItem + { + internal JumpItem() + { + } + + public string CustomCategory { get; set; } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/JumpItemRejectionReason.cs b/src/Shared/Microsoft.Windows.Shell/JumpItemRejectionReason.cs new file mode 100644 index 00000000..75fa583b --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/JumpItemRejectionReason.cs @@ -0,0 +1,12 @@ +using System; + +namespace Microsoft.Windows.Shell +{ + public enum JumpItemRejectionReason + { + None, + InvalidItem, + NoRegisteredHandler, + RemovedByUser + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/JumpItemsRejectedEventArgs.cs b/src/Shared/Microsoft.Windows.Shell/JumpItemsRejectedEventArgs.cs new file mode 100644 index 00000000..ba9d9097 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/JumpItemsRejectedEventArgs.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; + +namespace Microsoft.Windows.Shell +{ + public sealed class JumpItemsRejectedEventArgs : EventArgs + { + public JumpItemsRejectedEventArgs() : this(null, null) + { + } + + public JumpItemsRejectedEventArgs(IList rejectedItems, IList reasons) + { + if ((rejectedItems == null && reasons != null) || (reasons == null && rejectedItems != null) || (rejectedItems != null && reasons != null && rejectedItems.Count != reasons.Count)) + { + throw new ArgumentException("The counts of rejected items doesn't match the count of reasons."); + } + if (rejectedItems != null) + { + this.RejectedItems = new List(rejectedItems).AsReadOnly(); + this.RejectionReasons = new List(reasons).AsReadOnly(); + return; + } + this.RejectedItems = new List().AsReadOnly(); + this.RejectionReasons = new List().AsReadOnly(); + } + + public IList RejectedItems { get; private set; } + + public IList RejectionReasons { get; private set; } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/JumpItemsRemovedEventArgs.cs b/src/Shared/Microsoft.Windows.Shell/JumpItemsRemovedEventArgs.cs new file mode 100644 index 00000000..ddfdb0b0 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/JumpItemsRemovedEventArgs.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +namespace Microsoft.Windows.Shell +{ + public sealed class JumpItemsRemovedEventArgs : EventArgs + { + public JumpItemsRemovedEventArgs() : this(null) + { + } + + public JumpItemsRemovedEventArgs(IList removedItems) + { + if (removedItems != null) + { + this.RemovedItems = new List(removedItems).AsReadOnly(); + return; + } + this.RemovedItems = new List().AsReadOnly(); + } + + public IList RemovedItems { get; private set; } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/JumpList.cs b/src/Shared/Microsoft.Windows.Shell/JumpList.cs new file mode 100644 index 00000000..66ed6964 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/JumpList.cs @@ -0,0 +1,750 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; +using System.Windows; +using System.Windows.Markup; +using Standard; + +namespace Microsoft.Windows.Shell +{ + [ContentProperty("JumpItems")] + public sealed class JumpList : ISupportInitialize + { + public static void AddToRecentCategory(string itemPath) + { + Verify.FileExists(itemPath, "itemPath"); + itemPath = Path.GetFullPath(itemPath); + NativeMethods.SHAddToRecentDocs(itemPath); + } + + [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] + public static void AddToRecentCategory(JumpPath jumpPath) + { + Verify.IsNotNull(jumpPath, "jumpPath"); + JumpList.AddToRecentCategory(jumpPath.Path); + } + + public static void AddToRecentCategory(JumpTask jumpTask) + { + Verify.IsNotNull(jumpTask, "jumpTask"); + if (Utility.IsOSWindows7OrNewer) + { + IShellLinkW shellLinkW = JumpList.CreateLinkFromJumpTask(jumpTask, false); + try + { + if (shellLinkW != null) + { + NativeMethods.SHAddToRecentDocs(shellLinkW); + } + } + finally + { + Utility.SafeRelease(ref shellLinkW); + } + } + } + + public static void SetJumpList(Application application, JumpList value) + { + Verify.IsNotNull(application, "application"); + lock (JumpList.s_lock) + { + JumpList jumpList; + if (JumpList.s_applicationMap.TryGetValue(application, out jumpList) && jumpList != null) + { + jumpList._application = null; + } + JumpList.s_applicationMap[application] = value; + if (value != null) + { + value._application = application; + } + } + if (value != null) + { + value.ApplyFromApplication(); + } + } + + public static JumpList GetJumpList(Application application) + { + Verify.IsNotNull(application, "application"); + JumpList result; + JumpList.s_applicationMap.TryGetValue(application, out result); + return result; + } + + public JumpList() : this(null, false, false) + { + this._initializing = null; + } + + public JumpList(IEnumerable items, bool showFrequent, bool showRecent) + { + if (items != null) + { + this._jumpItems = new List(items); + } + else + { + this._jumpItems = new List(); + } + this.ShowFrequentCategory = showFrequent; + this.ShowRecentCategory = showRecent; + this._initializing = new bool?(false); + } + + public bool ShowFrequentCategory { get; set; } + + public bool ShowRecentCategory { get; set; } + + [SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")] + public List JumpItems + { + get + { + return this._jumpItems; + } + } + + private bool _IsUnmodified + { + get + { + return this._initializing == null && this.JumpItems.Count == 0 && !this.ShowRecentCategory && !this.ShowFrequentCategory; + } + } + + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "BeginInit")] + public void BeginInit() + { + if (!this._IsUnmodified) + { + throw new InvalidOperationException("Calls to BeginInit cannot be nested."); + } + this._initializing = new bool?(true); + } + + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "EndInit")] + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "BeginInit")] + public void EndInit() + { + if (this._initializing != true) + { + throw new NotSupportedException("Can't call EndInit without first calling BeginInit."); + } + this._initializing = new bool?(false); + this.ApplyFromApplication(); + } + + private static string _RuntimeId + { + get + { + string result; + HRESULT hrLeft = NativeMethods.GetCurrentProcessExplicitAppUserModelID(out result); + if (hrLeft == HRESULT.E_FAIL) + { + hrLeft = HRESULT.S_OK; + result = null; + } + hrLeft.ThrowIfFailed(); + return result; + } + } + + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "JumpList")] + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "EndInit")] + public void Apply() + { + if (this._initializing == true) + { + throw new InvalidOperationException("The JumpList can't be applied until EndInit has been called."); + } + this._initializing = new bool?(false); + this._ApplyList(); + } + + private void ApplyFromApplication() + { + if (this._initializing != true && !this._IsUnmodified) + { + this._initializing = new bool?(false); + } + if (this._application == Application.Current && this._initializing == false) + { + this._ApplyList(); + } + } + + [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Standard.Verify.IsApartmentState(System.Threading.ApartmentState,System.String)")] + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "JumpLists")] + private void _ApplyList() + { + Verify.IsApartmentState(ApartmentState.STA, "JumpLists can only be effected on STA threads."); + if (!Utility.IsOSWindows7OrNewer) + { + this.RejectEverything(); + return; + } + List jumpItems; + List list; + List list2; + try + { + this._BuildShellLists(out jumpItems, out list, out list2); + } + catch (Exception) + { + this.RejectEverything(); + return; + } + this._jumpItems = jumpItems; + EventHandler jumpItemsRejected = this.JumpItemsRejected; + EventHandler jumpItemsRemovedByUser = this.JumpItemsRemovedByUser; + if (list.Count > 0 && jumpItemsRejected != null) + { + List list3 = new List(list.Count); + List list4 = new List(list.Count); + foreach (JumpList._RejectedJumpItemPair rejectedJumpItemPair in list) + { + list3.Add(rejectedJumpItemPair.JumpItem); + list4.Add(rejectedJumpItemPair.Reason); + } + jumpItemsRejected(this, new JumpItemsRejectedEventArgs(list3, list4)); + } + if (list2.Count > 0 && jumpItemsRemovedByUser != null) + { + List list5 = new List(list2.Count); + foreach (JumpList._ShellObjectPair shellObjectPair in list2) + { + if (shellObjectPair.JumpItem != null) + { + list5.Add(shellObjectPair.JumpItem); + } + } + if (list5.Count > 0) + { + jumpItemsRemovedByUser(this, new JumpItemsRemovedEventArgs(list5)); + } + } + } + + private void _BuildShellLists(out List successList, out List rejectedList, out List removedList) + { + List> list = null; + removedList = null; + ICustomDestinationList customDestinationList = CLSID.CoCreateInstance("77f10cf0-3db5-4966-b520-b7c54fd35ed6"); + try + { + string runtimeId = JumpList._RuntimeId; + if (!string.IsNullOrEmpty(runtimeId)) + { + customDestinationList.SetAppID(runtimeId); + } + Guid guid = new Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9"); + uint num; + IObjectArray shellObjects = (IObjectArray)customDestinationList.BeginList(out num, ref guid); + removedList = JumpList.GenerateJumpItems(shellObjects); + successList = new List(this.JumpItems.Count); + rejectedList = new List(this.JumpItems.Count); + list = new List> + { + new List() + }; + foreach (JumpItem jumpItem in this.JumpItems) + { + if (jumpItem == null) + { + rejectedList.Add(new JumpList._RejectedJumpItemPair + { + JumpItem = jumpItem, + Reason = JumpItemRejectionReason.InvalidItem + }); + } + else + { + object obj = null; + try + { + obj = JumpList.GetShellObjectForJumpItem(jumpItem); + if (obj == null) + { + rejectedList.Add(new JumpList._RejectedJumpItemPair + { + Reason = JumpItemRejectionReason.InvalidItem, + JumpItem = jumpItem + }); + } + else if (JumpList.ListContainsShellObject(removedList, obj)) + { + rejectedList.Add(new JumpList._RejectedJumpItemPair + { + Reason = JumpItemRejectionReason.RemovedByUser, + JumpItem = jumpItem + }); + } + else + { + JumpList._ShellObjectPair item = new JumpList._ShellObjectPair + { + JumpItem = jumpItem, + ShellObject = obj + }; + if (string.IsNullOrEmpty(jumpItem.CustomCategory)) + { + list[0].Add(item); + } + else + { + bool flag = false; + foreach (List list2 in list) + { + if (list2.Count > 0 && list2[0].JumpItem.CustomCategory == jumpItem.CustomCategory) + { + list2.Add(item); + flag = true; + break; + } + } + if (!flag) + { + list.Add(new List + { + item + }); + } + } + obj = null; + } + } + finally + { + Utility.SafeRelease(ref obj); + } + } + } + list.Reverse(); + if (this.ShowFrequentCategory) + { + customDestinationList.AppendKnownCategory(KDC.FREQUENT); + } + if (this.ShowRecentCategory) + { + customDestinationList.AppendKnownCategory(KDC.RECENT); + } + foreach (List list3 in list) + { + if (list3.Count > 0) + { + string customCategory = list3[0].JumpItem.CustomCategory; + JumpList.AddCategory(customDestinationList, customCategory, list3, successList, rejectedList); + } + } + customDestinationList.CommitList(); + successList.Reverse(); + } + finally + { + Utility.SafeRelease(ref customDestinationList); + if (list != null) + { + foreach (List list4 in list) + { + JumpList._ShellObjectPair.ReleaseShellObjects(list4); + } + } + JumpList._ShellObjectPair.ReleaseShellObjects(removedList); + } + } + + private static bool ListContainsShellObject(List removedList, object shellObject) + { + if (removedList.Count == 0) + { + return false; + } + IShellItem shellItem = shellObject as IShellItem; + if (shellItem != null) + { + foreach (JumpList._ShellObjectPair shellObjectPair in removedList) + { + IShellItem shellItem2 = shellObjectPair.ShellObject as IShellItem; + if (shellItem2 != null && shellItem.Compare(shellItem2, (SICHINT)805306368u) == 0) + { + return true; + } + } + return false; + } + IShellLinkW shellLinkW = shellObject as IShellLinkW; + if (shellLinkW != null) + { + foreach (JumpList._ShellObjectPair shellObjectPair2 in removedList) + { + IShellLinkW shellLinkW2 = shellObjectPair2.ShellObject as IShellLinkW; + if (shellLinkW2 != null) + { + string a = JumpList.ShellLinkToString(shellLinkW2); + string b = JumpList.ShellLinkToString(shellLinkW); + if (a == b) + { + return true; + } + } + } + return false; + } + return false; + } + + private static object GetShellObjectForJumpItem(JumpItem jumpItem) + { + JumpPath jumpPath = jumpItem as JumpPath; + JumpTask jumpTask = jumpItem as JumpTask; + if (jumpPath != null) + { + return JumpList.CreateItemFromJumpPath(jumpPath); + } + if (jumpTask != null) + { + return JumpList.CreateLinkFromJumpTask(jumpTask, true); + } + return null; + } + + private static List GenerateJumpItems(IObjectArray shellObjects) + { + List list = new List(); + Guid guid = new Guid("00000000-0000-0000-C000-000000000046"); + uint count = shellObjects.GetCount(); + for (uint num = 0u; num < count; num += 1u) + { + object at = shellObjects.GetAt(num, ref guid); + JumpItem jumpItem = null; + try + { + jumpItem = JumpList.GetJumpItemForShellObject(at); + } + catch (Exception ex) + { + if (ex is NullReferenceException || ex is SEHException) + { + throw; + } + } + list.Add(new JumpList._ShellObjectPair + { + ShellObject = at, + JumpItem = jumpItem + }); + } + return list; + } + + private static void AddCategory(ICustomDestinationList cdl, string category, List jumpItems, List successList, List rejectionList) + { + JumpList.AddCategory(cdl, category, jumpItems, successList, rejectionList, true); + } + + private static void AddCategory(ICustomDestinationList cdl, string category, List jumpItems, List successList, List rejectionList, bool isHeterogenous) + { + IObjectCollection objectCollection = (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("2d3468c1-36a7-43b6-ac24-d3f02fd9607a"))); + foreach (JumpList._ShellObjectPair shellObjectPair in jumpItems) + { + objectCollection.AddObject(shellObjectPair.ShellObject); + } + HRESULT hrLeft; + if (string.IsNullOrEmpty(category)) + { + hrLeft = cdl.AddUserTasks(objectCollection); + } + else + { + hrLeft = cdl.AppendCategory(category, objectCollection); + } + if (hrLeft.Succeeded) + { + int num = jumpItems.Count; + while (--num >= 0) + { + successList.Add(jumpItems[num].JumpItem); + } + return; + } + if (isHeterogenous && hrLeft == HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER) + { + Utility.SafeRelease(ref objectCollection); + List list = new List(); + foreach (JumpList._ShellObjectPair shellObjectPair2 in jumpItems) + { + if (shellObjectPair2.JumpItem is JumpPath) + { + rejectionList.Add(new JumpList._RejectedJumpItemPair + { + JumpItem = shellObjectPair2.JumpItem, + Reason = JumpItemRejectionReason.NoRegisteredHandler + }); + } + else + { + list.Add(shellObjectPair2); + } + } + if (list.Count > 0) + { + JumpList.AddCategory(cdl, category, list, successList, rejectionList, false); + return; + } + } + else + { + foreach (JumpList._ShellObjectPair shellObjectPair3 in jumpItems) + { + rejectionList.Add(new JumpList._RejectedJumpItemPair + { + JumpItem = shellObjectPair3.JumpItem, + Reason = JumpItemRejectionReason.InvalidItem + }); + } + } + } + + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] + private static IShellLinkW CreateLinkFromJumpTask(JumpTask jumpTask, bool allowSeparators) + { + if (string.IsNullOrEmpty(jumpTask.Title) && (!allowSeparators || !string.IsNullOrEmpty(jumpTask.CustomCategory))) + { + return null; + } + IShellLinkW shellLinkW = (IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"))); + IShellLinkW result; + try + { + string path = JumpList._FullName; + if (!string.IsNullOrEmpty(jumpTask.ApplicationPath)) + { + path = jumpTask.ApplicationPath; + } + shellLinkW.SetPath(path); + if (!string.IsNullOrEmpty(jumpTask.WorkingDirectory)) + { + shellLinkW.SetWorkingDirectory(jumpTask.WorkingDirectory); + } + if (!string.IsNullOrEmpty(jumpTask.Arguments)) + { + shellLinkW.SetArguments(jumpTask.Arguments); + } + if (jumpTask.IconResourceIndex != -1) + { + string pszIconPath = JumpList._FullName; + if (!string.IsNullOrEmpty(jumpTask.IconResourcePath)) + { + if ((long)jumpTask.IconResourcePath.Length >= 260L) + { + return null; + } + pszIconPath = jumpTask.IconResourcePath; + } + shellLinkW.SetIconLocation(pszIconPath, jumpTask.IconResourceIndex); + } + if (!string.IsNullOrEmpty(jumpTask.Description)) + { + shellLinkW.SetDescription(jumpTask.Description); + } + IPropertyStore propertyStore = (IPropertyStore)shellLinkW; + using (PROPVARIANT propvariant = new PROPVARIANT()) + { + PKEY pkey = default(PKEY); + if (!string.IsNullOrEmpty(jumpTask.Title)) + { + propvariant.SetValue(jumpTask.Title); + pkey = PKEY.Title; + } + else + { + propvariant.SetValue(true); + pkey = PKEY.AppUserModel_IsDestListSeparator; + } + propertyStore.SetValue(ref pkey, propvariant); + } + propertyStore.Commit(); + IShellLinkW shellLinkW2 = shellLinkW; + shellLinkW = null; + result = shellLinkW2; + } + catch (Exception) + { + result = null; + } + finally + { + Utility.SafeRelease(ref shellLinkW); + } + return result; + } + + private static IShellItem2 GetShellItemForPath(string path) + { + if (string.IsNullOrEmpty(path)) + { + return null; + } + Guid guid = new Guid("7e9fb0d3-919f-4307-ab2e-9b1860310c93"); + object obj; + HRESULT hrLeft = NativeMethods.SHCreateItemFromParsingName(path, null, ref guid, out obj); + if (hrLeft == (HRESULT)Win32Error.ERROR_FILE_NOT_FOUND || hrLeft == (HRESULT)Win32Error.ERROR_PATH_NOT_FOUND) + { + hrLeft = HRESULT.S_OK; + obj = null; + } + hrLeft.ThrowIfFailed(); + return (IShellItem2)obj; + } + + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] + private static IShellItem2 CreateItemFromJumpPath(JumpPath jumpPath) + { + try + { + return JumpList.GetShellItemForPath(Path.GetFullPath(jumpPath.Path)); + } + catch (Exception) + { + } + return null; + } + + private static JumpItem GetJumpItemForShellObject(object shellObject) + { + IShellItem2 shellItem = shellObject as IShellItem2; + IShellLinkW shellLinkW = shellObject as IShellLinkW; + if (shellItem != null) + { + return new JumpPath + { + Path = shellItem.GetDisplayName((SIGDN)2147647488u) + }; + } + if (shellLinkW != null) + { + StringBuilder stringBuilder = new StringBuilder(260); + shellLinkW.GetPath(stringBuilder, stringBuilder.Capacity, null, SLGP.RAWPATH); + StringBuilder stringBuilder2 = new StringBuilder(1024); + shellLinkW.GetArguments(stringBuilder2, stringBuilder2.Capacity); + StringBuilder stringBuilder3 = new StringBuilder(1024); + shellLinkW.GetDescription(stringBuilder3, stringBuilder3.Capacity); + StringBuilder stringBuilder4 = new StringBuilder(260); + int iconResourceIndex; + shellLinkW.GetIconLocation(stringBuilder4, stringBuilder4.Capacity, out iconResourceIndex); + StringBuilder stringBuilder5 = new StringBuilder(260); + shellLinkW.GetWorkingDirectory(stringBuilder5, stringBuilder5.Capacity); + JumpTask jumpTask = new JumpTask + { + ApplicationPath = stringBuilder.ToString(), + Arguments = stringBuilder2.ToString(), + Description = stringBuilder3.ToString(), + IconResourceIndex = iconResourceIndex, + IconResourcePath = stringBuilder4.ToString(), + WorkingDirectory = stringBuilder5.ToString() + }; + using (PROPVARIANT propvariant = new PROPVARIANT()) + { + IPropertyStore propertyStore = (IPropertyStore)shellLinkW; + PKEY title = PKEY.Title; + propertyStore.GetValue(ref title, propvariant); + jumpTask.Title = (propvariant.GetValue() ?? ""); + } + return jumpTask; + } + return null; + } + + private static string ShellLinkToString(IShellLinkW shellLink) + { + StringBuilder stringBuilder = new StringBuilder(260); + shellLink.GetPath(stringBuilder, stringBuilder.Capacity, null, SLGP.RAWPATH); + string text = null; + using (PROPVARIANT propvariant = new PROPVARIANT()) + { + IPropertyStore propertyStore = (IPropertyStore)shellLink; + PKEY title = PKEY.Title; + propertyStore.GetValue(ref title, propvariant); + text = (propvariant.GetValue() ?? ""); + } + StringBuilder stringBuilder2 = new StringBuilder(1024); + shellLink.GetArguments(stringBuilder2, stringBuilder2.Capacity); + return stringBuilder.ToString().ToUpperInvariant() + text.ToUpperInvariant() + stringBuilder2.ToString(); + } + + private void RejectEverything() + { + EventHandler jumpItemsRejected = this.JumpItemsRejected; + if (jumpItemsRejected == null) + { + this._jumpItems.Clear(); + return; + } + if (this._jumpItems.Count > 0) + { + List list = new List(this.JumpItems.Count); + for (int i = 0; i < this.JumpItems.Count; i++) + { + list.Add(JumpItemRejectionReason.InvalidItem); + } + JumpItemsRejectedEventArgs e = new JumpItemsRejectedEventArgs(this.JumpItems, list); + this._jumpItems.Clear(); + jumpItemsRejected(this, e); + } + } + + public event EventHandler JumpItemsRejected; + + public event EventHandler JumpItemsRemovedByUser; + + private static readonly object s_lock = new object(); + + private static readonly Dictionary s_applicationMap = new Dictionary(); + + private Application _application; + + private bool? _initializing; + + private List _jumpItems; + + private static readonly string _FullName = NativeMethods.GetModuleFileName(IntPtr.Zero); + + private class _RejectedJumpItemPair + { + public JumpItem JumpItem { get; set; } + + public JumpItemRejectionReason Reason { get; set; } + } + + private class _ShellObjectPair + { + public JumpItem JumpItem { get; set; } + + public object ShellObject { get; set; } + + public static void ReleaseShellObjects(List list) + { + if (list != null) + { + foreach (JumpList._ShellObjectPair shellObjectPair in list) + { + object shellObject = shellObjectPair.ShellObject; + shellObjectPair.ShellObject = null; + Utility.SafeRelease(ref shellObject); + } + } + } + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/JumpPath.cs b/src/Shared/Microsoft.Windows.Shell/JumpPath.cs new file mode 100644 index 00000000..0cec68f4 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/JumpPath.cs @@ -0,0 +1,9 @@ +using System; + +namespace Microsoft.Windows.Shell +{ + public class JumpPath : JumpItem + { + public string Path { get; set; } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/JumpTask.cs b/src/Shared/Microsoft.Windows.Shell/JumpTask.cs new file mode 100644 index 00000000..d49ffb46 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/JumpTask.cs @@ -0,0 +1,21 @@ +using System; + +namespace Microsoft.Windows.Shell +{ + public class JumpTask : JumpItem + { + public string Title { get; set; } + + public string Description { get; set; } + + public string ApplicationPath { get; set; } + + public string Arguments { get; set; } + + public string WorkingDirectory { get; set; } + + public string IconResourcePath { get; set; } + + public int IconResourceIndex { get; set; } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Microsoft.Windows.Shell.projitems b/src/Shared/Microsoft.Windows.Shell/Microsoft.Windows.Shell.projitems new file mode 100644 index 00000000..b2324034 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Microsoft.Windows.Shell.projitems @@ -0,0 +1,169 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + bbe51380-8b21-49ff-9cfc-b29447a40999 + + + SharedProject1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Shared/Microsoft.Windows.Shell/Microsoft.Windows.Shell.shproj b/src/Shared/Microsoft.Windows.Shell/Microsoft.Windows.Shell.shproj new file mode 100644 index 00000000..996bce7e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Microsoft.Windows.Shell.shproj @@ -0,0 +1,13 @@ + + + + bbe51380-8b21-49ff-9cfc-b29447a40999 + 14.0 + + + + + + + + diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/AC.cs b/src/Shared/Microsoft.Windows.Shell/Standard/AC.cs new file mode 100644 index 00000000..5ea00a24 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/AC.cs @@ -0,0 +1,10 @@ +using System; + +namespace Standard +{ + internal enum AC : byte + { + SRC_OVER, + SRC_ALPHA + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/APPDOCLISTTYPE.cs b/src/Shared/Microsoft.Windows.Shell/Standard/APPDOCLISTTYPE.cs new file mode 100644 index 00000000..24f09f3e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/APPDOCLISTTYPE.cs @@ -0,0 +1,10 @@ +using System; + +namespace Standard +{ + internal enum APPDOCLISTTYPE + { + ADLT_RECENT, + ADLT_FREQUENT + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/Assert.cs b/src/Shared/Microsoft.Windows.Shell/Standard/Assert.cs new file mode 100644 index 00000000..603c477a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/Assert.cs @@ -0,0 +1,233 @@ +using System; +using System.Diagnostics; +using System.Threading; +using System.Windows; + +namespace Standard +{ + internal static class Assert + { + private static void _Break() + { + Debugger.Break(); + } + + [Conditional("DEBUG")] + public static void Evaluate(Assert.EvaluateFunction argument) + { + argument(); + } + + [Obsolete("Use Assert.AreEqual instead of Assert.Equals", false)] + [Conditional("DEBUG")] + public static void Equals(T expected, T actual) + { + } + + [Conditional("DEBUG")] + public static void AreEqual(T expected, T actual) + { + if (expected == null) + { + if (actual != null && !actual.Equals(expected)) + { + Assert._Break(); + return; + } + } + else if (!expected.Equals(actual)) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void AreNotEqual(T notExpected, T actual) + { + if (notExpected == null) + { + if (actual == null || actual.Equals(notExpected)) + { + Assert._Break(); + return; + } + } + else if (notExpected.Equals(actual)) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void Implies(bool condition, bool result) + { + if (condition && !result) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void Implies(bool condition, Assert.ImplicationFunction result) + { + if (condition && !result()) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void IsNeitherNullNorEmpty(string value) + { + } + + [Conditional("DEBUG")] + public static void IsNeitherNullNorWhitespace(string value) + { + if (string.IsNullOrEmpty(value)) + { + Assert._Break(); + } + if (value.Trim().Length == 0) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void IsNotNull(T value) where T : class + { + if (value == null) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void IsDefault(T value) where T : struct + { + value.Equals(default(T)); + } + + [Conditional("DEBUG")] + public static void IsNotDefault(T value) where T : struct + { + value.Equals(default(T)); + } + + [Conditional("DEBUG")] + public static void IsFalse(bool condition) + { + if (condition) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void IsFalse(bool condition, string message) + { + if (condition) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void IsTrue(bool condition) + { + if (!condition) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void IsTrue(bool condition, string message) + { + if (!condition) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void Fail() + { + Assert._Break(); + } + + [Conditional("DEBUG")] + public static void Fail(string message) + { + Assert._Break(); + } + + [Conditional("DEBUG")] + public static void IsNull(T item) where T : class + { + if (item != null) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive) + { + if (value < lowerBoundInclusive || value > upperBoundInclusive) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive) + { + if (value < lowerBoundInclusive || value >= upperBoundExclusive) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void IsApartmentState(ApartmentState expectedState) + { + if (Thread.CurrentThread.GetApartmentState() != expectedState) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void NullableIsNotNull(T? value) where T : struct + { + if (value == null) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void NullableIsNull(T? value) where T : struct + { + if (value != null) + { + Assert._Break(); + } + } + + [Conditional("DEBUG")] + public static void IsNotOnMainThread() + { + if (Application.Current.Dispatcher.CheckAccess()) + { + Assert._Break(); + } + } + + public delegate void EvaluateFunction(); + + public delegate bool ImplicationFunction(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/BI.cs b/src/Shared/Microsoft.Windows.Shell/Standard/BI.cs new file mode 100644 index 00000000..90d1914a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/BI.cs @@ -0,0 +1,9 @@ +using System; + +namespace Standard +{ + internal enum BI + { + RGB + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/BITMAPINFO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/BITMAPINFO.cs new file mode 100644 index 00000000..fc3ff7ca --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/BITMAPINFO.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal struct BITMAPINFO + { + public BITMAPINFOHEADER bmiHeader; + + public RGBQUAD bmiColors; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/BITMAPINFOHEADER.cs b/src/Shared/Microsoft.Windows.Shell/Standard/BITMAPINFOHEADER.cs new file mode 100644 index 00000000..773a7285 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/BITMAPINFOHEADER.cs @@ -0,0 +1,31 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential, Pack = 2)] + internal struct BITMAPINFOHEADER + { + public int biSize; + + public int biWidth; + + public int biHeight; + + public short biPlanes; + + public short biBitCount; + + public BI biCompression; + + public int biSizeImage; + + public int biXPelsPerMeter; + + public int biYPelsPerMeter; + + public int biClrUsed; + + public int biClrImportant; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/BLENDFUNCTION.cs b/src/Shared/Microsoft.Windows.Shell/Standard/BLENDFUNCTION.cs new file mode 100644 index 00000000..ddca67a1 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/BLENDFUNCTION.cs @@ -0,0 +1,15 @@ +using System; + +namespace Standard +{ + internal struct BLENDFUNCTION + { + public AC BlendOp; + + public byte BlendFlags; + + public byte SourceConstantAlpha; + + public AC AlphaFormat; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/CHANGEFILTERSTRUCT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/CHANGEFILTERSTRUCT.cs new file mode 100644 index 00000000..e24872f0 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/CHANGEFILTERSTRUCT.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal struct CHANGEFILTERSTRUCT + { + public uint cbSize; + + public MSGFLTINFO ExtStatus; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/CLSID.cs b/src/Shared/Microsoft.Windows.Shell/Standard/CLSID.cs new file mode 100644 index 00000000..bf79a5dc --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/CLSID.cs @@ -0,0 +1,24 @@ +using System; + +namespace Standard +{ + internal static class CLSID + { + public static T CoCreateInstance(string clsid) + { + return (T)((object)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(clsid)))); + } + + public const string TaskbarList = "56FDF344-FD6D-11d0-958A-006097C9A090"; + + public const string EnumerableObjectCollection = "2d3468c1-36a7-43b6-ac24-d3f02fd9607a"; + + public const string ShellLink = "00021401-0000-0000-C000-000000000046"; + + public const string DestinationList = "77f10cf0-3db5-4966-b520-b7c54fd35ed6"; + + public const string ApplicationDestinations = "86c14003-4d6b-4ef3-a7b4-0506663b2e68"; + + public const string ApplicationDocumentLists = "86bec222-30f2-47e0-9f25-60d11cd75c28"; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/CREATESTRUCT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/CREATESTRUCT.cs new file mode 100644 index 00000000..f237908e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/CREATESTRUCT.cs @@ -0,0 +1,35 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + internal struct CREATESTRUCT + { + public IntPtr lpCreateParams; + + public IntPtr hInstance; + + public IntPtr hMenu; + + public IntPtr hwndParent; + + public int cy; + + public int cx; + + public int y; + + public int x; + + public WS style; + + [MarshalAs(UnmanagedType.LPWStr)] + public string lpszName; + + [MarshalAs(UnmanagedType.LPWStr)] + public string lpszClass; + + public WS_EX dwExStyle; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/CS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/CS.cs new file mode 100644 index 00000000..0e036b49 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/CS.cs @@ -0,0 +1,22 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum CS : uint + { + VREDRAW = 1u, + HREDRAW = 2u, + DBLCLKS = 8u, + OWNDC = 32u, + CLASSDC = 64u, + PARENTDC = 128u, + NOCLOSE = 512u, + SAVEBITS = 2048u, + BYTEALIGNCLIENT = 4096u, + BYTEALIGNWINDOW = 8192u, + GLOBALCLASS = 16384u, + IME = 65536u, + DROPSHADOW = 131072u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/CombineRgnResult.cs b/src/Shared/Microsoft.Windows.Shell/Standard/CombineRgnResult.cs new file mode 100644 index 00000000..1d6848fa --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/CombineRgnResult.cs @@ -0,0 +1,12 @@ +using System; + +namespace Standard +{ + internal enum CombineRgnResult + { + ERROR, + NULLREGION, + SIMPLEREGION, + COMPLEXREGION + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DOGIF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DOGIF.cs new file mode 100644 index 00000000..20bc745a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DOGIF.cs @@ -0,0 +1,13 @@ +using System; + +namespace Standard +{ + internal enum DOGIF + { + DEFAULT, + TRAVERSE_LINK, + NO_HDROP, + NO_URL = 4, + ONLY_IF_ONE = 8 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DWMFLIP3D.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DWMFLIP3D.cs new file mode 100644 index 00000000..2f4c07d9 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DWMFLIP3D.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal enum DWMFLIP3D + { + DEFAULT, + EXCLUDEBELOW, + EXCLUDEABOVE + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DWMNCRP.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DWMNCRP.cs new file mode 100644 index 00000000..6fddb087 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DWMNCRP.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal enum DWMNCRP + { + USEWINDOWSTYLE, + DISABLED, + ENABLED + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DWMWA.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DWMWA.cs new file mode 100644 index 00000000..723e09ea --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DWMWA.cs @@ -0,0 +1,20 @@ +using System; + +namespace Standard +{ + internal enum DWMWA + { + NCRENDERING_ENABLED = 1, + NCRENDERING_POLICY, + TRANSITIONS_FORCEDISABLED, + ALLOW_NCPAINT, + CAPTION_BUTTON_BOUNDS, + NONCLIENT_RTL_LAYOUT, + FORCE_ICONIC_REPRESENTATION, + FLIP3D_POLICY, + EXTENDED_FRAME_BOUNDS, + HAS_ICONIC_BITMAP, + DISALLOW_PEEK, + EXCLUDED_FROM_PEEK + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DWM_SIT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DWM_SIT.cs new file mode 100644 index 00000000..332476ca --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DWM_SIT.cs @@ -0,0 +1,10 @@ +using System; + +namespace Standard +{ + internal enum DWM_SIT + { + None, + DISPLAYFRAME + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DWM_TIMING_INFO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DWM_TIMING_INFO.cs new file mode 100644 index 00000000..5835befa --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DWM_TIMING_INFO.cs @@ -0,0 +1,89 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential, Pack = 1)] + internal struct DWM_TIMING_INFO + { + public int cbSize; + + public UNSIGNED_RATIO rateRefresh; + + public ulong qpcRefreshPeriod; + + public UNSIGNED_RATIO rateCompose; + + public ulong qpcVBlank; + + public ulong cRefresh; + + public uint cDXRefresh; + + public ulong qpcCompose; + + public ulong cFrame; + + public uint cDXPresent; + + public ulong cRefreshFrame; + + public ulong cFrameSubmitted; + + public uint cDXPresentSubmitted; + + public ulong cFrameConfirmed; + + public uint cDXPresentConfirmed; + + public ulong cRefreshConfirmed; + + public uint cDXRefreshConfirmed; + + public ulong cFramesLate; + + public uint cFramesOutstanding; + + public ulong cFrameDisplayed; + + public ulong qpcFrameDisplayed; + + public ulong cRefreshFrameDisplayed; + + public ulong cFrameComplete; + + public ulong qpcFrameComplete; + + public ulong cFramePending; + + public ulong qpcFramePending; + + public ulong cFramesDisplayed; + + public ulong cFramesComplete; + + public ulong cFramesPending; + + public ulong cFramesAvailable; + + public ulong cFramesDropped; + + public ulong cFramesMissed; + + public ulong cRefreshNextDisplayed; + + public ulong cRefreshNextPresented; + + public ulong cRefreshesDisplayed; + + public ulong cRefreshesPresented; + + public ulong cRefreshStarted; + + public ulong cPixelsReceived; + + public ulong cPixelsDrawn; + + public ulong cBuffersEmpty; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DeviceCap.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DeviceCap.cs new file mode 100644 index 00000000..50cc63af --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DeviceCap.cs @@ -0,0 +1,12 @@ +using System; + +namespace Standard +{ + internal enum DeviceCap + { + BITSPIXEL = 12, + PLANES = 14, + LOGPIXELSX = 88, + LOGPIXELSY = 90 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DoubleUtilities.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DoubleUtilities.cs new file mode 100644 index 00000000..66353816 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DoubleUtilities.cs @@ -0,0 +1,57 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Standard +{ + internal static class DoubleUtilities + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool AreClose(double value1, double value2) + { + if (value1 == value2) + { + return true; + } + double num = value1 - value2; + return num < 1.53E-06 && num > -1.53E-06; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool LessThan(double value1, double value2) + { + return value1 < value2 && !DoubleUtilities.AreClose(value1, value2); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool GreaterThan(double value1, double value2) + { + return value1 > value2 && !DoubleUtilities.AreClose(value1, value2); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool LessThanOrClose(double value1, double value2) + { + return value1 < value2 || DoubleUtilities.AreClose(value1, value2); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool GreaterThanOrClose(double value1, double value2) + { + return value1 > value2 || DoubleUtilities.AreClose(value1, value2); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool IsFinite(double value) + { + return !double.IsNaN(value) && !double.IsInfinity(value); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool IsValidSize(double value) + { + return DoubleUtilities.IsFinite(value) && DoubleUtilities.GreaterThanOrClose(value, 0.0); + } + + private const double Epsilon = 1.53E-06; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/DpiHelper.cs b/src/Shared/Microsoft.Windows.Shell/Standard/DpiHelper.cs new file mode 100644 index 00000000..000cb4de --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/DpiHelper.cs @@ -0,0 +1,70 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Windows; +using System.Windows.Media; + +namespace Standard +{ + internal static class DpiHelper + { + [SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")] + static DpiHelper() + { + using (SafeDC desktop = SafeDC.GetDesktop()) + { + int deviceCaps = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSX); + int deviceCaps2 = NativeMethods.GetDeviceCaps(desktop, DeviceCap.LOGPIXELSY); + DpiHelper._transformToDip = Matrix.Identity; + DpiHelper._transformToDip.Scale(96.0 / (double)deviceCaps, 96.0 / (double)deviceCaps2); + DpiHelper._transformToDevice = Matrix.Identity; + DpiHelper._transformToDevice.Scale((double)deviceCaps / 96.0, (double)deviceCaps2 / 96.0); + } + } + + public static Point LogicalPixelsToDevice(Point logicalPoint) + { + return DpiHelper._transformToDevice.Transform(logicalPoint); + } + + public static Point DevicePixelsToLogical(Point devicePoint) + { + return DpiHelper._transformToDip.Transform(devicePoint); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static Rect LogicalRectToDevice(Rect logicalRectangle) + { + Point point = DpiHelper.LogicalPixelsToDevice(new Point(logicalRectangle.Left, logicalRectangle.Top)); + Point point2 = DpiHelper.LogicalPixelsToDevice(new Point(logicalRectangle.Right, logicalRectangle.Bottom)); + return new Rect(point, point2); + } + + public static Rect DeviceRectToLogical(Rect deviceRectangle) + { + Point point = DpiHelper.DevicePixelsToLogical(new Point(deviceRectangle.Left, deviceRectangle.Top)); + Point point2 = DpiHelper.DevicePixelsToLogical(new Point(deviceRectangle.Right, deviceRectangle.Bottom)); + return new Rect(point, point2); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static Size LogicalSizeToDevice(Size logicalSize) + { + Point point = DpiHelper.LogicalPixelsToDevice(new Point(logicalSize.Width, logicalSize.Height)); + return new Size + { + Width = point.X, + Height = point.Y + }; + } + + public static Size DeviceSizeToLogical(Size deviceSize) + { + Point point = DpiHelper.DevicePixelsToLogical(new Point(deviceSize.Width, deviceSize.Height)); + return new Size(point.X, point.Y); + } + + private static Matrix _transformToDevice; + + private static Matrix _transformToDip; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/ErrorModes.cs b/src/Shared/Microsoft.Windows.Shell/Standard/ErrorModes.cs new file mode 100644 index 00000000..d2413688 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/ErrorModes.cs @@ -0,0 +1,14 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum ErrorModes + { + Default = 0, + FailCriticalErrors = 1, + NoGpFaultErrorBox = 2, + NoAlignmentFaultExcept = 4, + NoOpenFileErrorBox = 32768 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/FO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/FO.cs new file mode 100644 index 00000000..e2fae172 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/FO.cs @@ -0,0 +1,12 @@ +using System; + +namespace Standard +{ + internal enum FO + { + MOVE = 1, + COPY, + DELETE, + RENAME + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/FOF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/FOF.cs new file mode 100644 index 00000000..09b6b926 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/FOF.cs @@ -0,0 +1,24 @@ +using System; + +namespace Standard +{ + internal enum FOF : ushort + { + MULTIDESTFILES = 1, + CONFIRMMOUSE, + SILENT = 4, + RENAMEONCOLLISION = 8, + NOCONFIRMATION = 16, + WANTMAPPINGHANDLE = 32, + ALLOWUNDO = 64, + FILESONLY = 128, + SIMPLEPROGRESS = 256, + NOCONFIRMMKDIR = 512, + NOERRORUI = 1024, + NOCOPYSECURITYATTRIBS = 2048, + NORECURSION = 4096, + NO_CONNECTED_ELEMENTS = 8192, + WANTNUKEWARNING = 16384, + NORECURSEREPARSE = 32768 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/Facility.cs b/src/Shared/Microsoft.Windows.Shell/Standard/Facility.cs new file mode 100644 index 00000000..9c91841a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/Facility.cs @@ -0,0 +1,19 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum Facility + { + Null, + Rpc, + Dispatch, + Storage, + Itf, + Win32 = 7, + Windows, + Control = 10, + Ese = 3678, + WinCodec = 2200 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/GCLP.cs b/src/Shared/Microsoft.Windows.Shell/Standard/GCLP.cs new file mode 100644 index 00000000..ee56c454 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/GCLP.cs @@ -0,0 +1,9 @@ +using System; + +namespace Standard +{ + internal enum GCLP + { + HBRBACKGROUND = -10 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/GPS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/GPS.cs new file mode 100644 index 00000000..3f8d3d3d --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/GPS.cs @@ -0,0 +1,18 @@ +using System; + +namespace Standard +{ + internal enum GPS + { + DEFAULT, + HANDLERPROPERTIESONLY, + READWRITE, + TEMPORARY = 4, + FASTPROPERTIESONLY = 8, + OPENSLOWITEM = 16, + DELAYCREATION = 32, + BESTEFFORT = 64, + NO_OPLOCK = 128, + MASK_VALID = 255 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/GWL.cs b/src/Shared/Microsoft.Windows.Shell/Standard/GWL.cs new file mode 100644 index 00000000..277cd460 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/GWL.cs @@ -0,0 +1,15 @@ +using System; + +namespace Standard +{ + internal enum GWL + { + WNDPROC = -4, + HINSTANCE = -6, + HWNDPARENT = -8, + STYLE = -16, + EXSTYLE = -20, + USERDATA = -21, + ID = -12 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/HCF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/HCF.cs new file mode 100644 index 00000000..5272a7ec --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/HCF.cs @@ -0,0 +1,16 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum HCF + { + HIGHCONTRASTON = 1, + AVAILABLE = 2, + HOTKEYACTIVE = 4, + CONFIRMHOTKEY = 8, + HOTKEYSOUND = 16, + INDICATOR = 32, + HOTKEYAVAILABLE = 64 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/HIGHCONTRAST.cs b/src/Shared/Microsoft.Windows.Shell/Standard/HIGHCONTRAST.cs new file mode 100644 index 00000000..f2e1b199 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/HIGHCONTRAST.cs @@ -0,0 +1,13 @@ +using System; + +namespace Standard +{ + internal struct HIGHCONTRAST + { + public int cbSize; + + public HCF dwFlags; + + public IntPtr lpszDefaultScheme; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/HRESULT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/HRESULT.cs new file mode 100644 index 00000000..6ec17fd6 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/HRESULT.cs @@ -0,0 +1,244 @@ +using System; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Reflection; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Explicit)] + internal struct HRESULT + { + public HRESULT(uint i) + { + this._value = i; + } + + public static HRESULT Make(bool severe, Facility facility, int code) + { + return new HRESULT((uint)((severe ? (Facility)(-2147483648) : Facility.Null) | (Facility) ((int)facility << 16) | (Facility)code)); + } + + public Facility Facility + { + get + { + return HRESULT.GetFacility((int)this._value); + } + } + + public static Facility GetFacility(int errorCode) + { + return (Facility)(errorCode >> 16 & 8191); + } + + public int Code + { + get + { + return HRESULT.GetCode((int)this._value); + } + } + + public static int GetCode(int error) + { + return error & 65535; + } + + public override string ToString() + { + foreach (FieldInfo fieldInfo in typeof(HRESULT).GetFields(BindingFlags.Static | BindingFlags.Public)) + { + if (fieldInfo.FieldType == typeof(HRESULT)) + { + HRESULT hrLeft = (HRESULT)fieldInfo.GetValue(null); + if (hrLeft == this) + { + return fieldInfo.Name; + } + } + } + if (this.Facility == Facility.Win32) + { + foreach (FieldInfo fieldInfo2 in typeof(Win32Error).GetFields(BindingFlags.Static | BindingFlags.Public)) + { + if (fieldInfo2.FieldType == typeof(Win32Error)) + { + Win32Error error = (Win32Error)fieldInfo2.GetValue(null); + if ((HRESULT)error == this) + { + return "HRESULT_FROM_WIN32(" + fieldInfo2.Name + ")"; + } + } + } + } + return string.Format(CultureInfo.InvariantCulture, "0x{0:X8}", new object[] + { + this._value + }); + } + + public override bool Equals(object obj) + { + bool result; + try + { + result = (((HRESULT)obj)._value == this._value); + } + catch (InvalidCastException) + { + result = false; + } + return result; + } + + public override int GetHashCode() + { + return this._value.GetHashCode(); + } + + public static bool operator ==(HRESULT hrLeft, HRESULT hrRight) + { + return hrLeft._value == hrRight._value; + } + + public static bool operator !=(HRESULT hrLeft, HRESULT hrRight) + { + return !(hrLeft == hrRight); + } + + public bool Succeeded + { + get + { + return this._value >= 0u; + } + } + + public bool Failed + { + get + { + return this._value < 0u; + } + } + + public void ThrowIfFailed() + { + this.ThrowIfFailed(null); + } + + [SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes", Justification = "Only recreating Exceptions that were already raised.")] + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public void ThrowIfFailed(string message) + { + if (this.Failed) + { + if (string.IsNullOrEmpty(message)) + { + message = this.ToString(); + } + Exception ex = Marshal.GetExceptionForHR((int)this._value, new IntPtr(-1)); + if (ex.GetType() == typeof(COMException)) + { + Facility facility = this.Facility; + if (facility == Facility.Win32) + { + ex = new Win32Exception(this.Code, message); + } + else + { + ex = new COMException(message, (int)this._value); + } + } + else + { + ConstructorInfo constructor = ex.GetType().GetConstructor(new Type[] + { + typeof(string) + }); + if (null != constructor) + { + ex = (constructor.Invoke(new object[] + { + message + }) as Exception); + } + } + throw ex; + } + } + + public static void ThrowLastError() + { + ((HRESULT)Win32Error.GetLastError()).ThrowIfFailed(); + } + + [FieldOffset(0)] + private readonly uint _value; + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT S_OK = new HRESULT(0u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT S_FALSE = new HRESULT(1u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_PENDING = new HRESULT(2147483658u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_NOTIMPL = new HRESULT(2147500033u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_NOINTERFACE = new HRESULT(2147500034u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_POINTER = new HRESULT(2147500035u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_ABORT = new HRESULT(2147500036u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_FAIL = new HRESULT(2147500037u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_UNEXPECTED = new HRESULT(2147549183u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT STG_E_INVALIDFUNCTION = new HRESULT(2147680257u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT REGDB_E_CLASSNOTREG = new HRESULT(2147746132u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT DESTS_E_NO_MATCHING_ASSOC_HANDLER = new HRESULT(2147749635u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT DESTS_E_NORECDOCS = new HRESULT(2147749636u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT DESTS_E_NOTALLCLEARED = new HRESULT(2147749637u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_ACCESSDENIED = new HRESULT(2147942405u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_OUTOFMEMORY = new HRESULT(2147942414u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT E_INVALIDARG = new HRESULT(2147942487u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT INTSAFE_E_ARITHMETIC_OVERFLOW = new HRESULT(2147942934u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT COR_E_OBJECTDISPOSED = new HRESULT(2148734498u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT WC_E_GREATERTHAN = new HRESULT(3222072867u); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly HRESULT WC_E_SYNTAX = new HRESULT(3222072877u); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/HT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/HT.cs new file mode 100644 index 00000000..abb24d4f --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/HT.cs @@ -0,0 +1,37 @@ +using System; + +namespace Standard +{ + internal enum HT + { + ERROR = -2, + TRANSPARENT, + NOWHERE, + CLIENT, + CAPTION, + SYSMENU, + GROWBOX, + SIZE = 4, + MENU, + HSCROLL, + VSCROLL, + MINBUTTON, + MAXBUTTON, + LEFT, + RIGHT, + TOP, + TOPLEFT, + TOPRIGHT, + BOTTOM, + BOTTOMLEFT, + BOTTOMRIGHT, + BORDER, + REDUCE = 8, + ZOOM, + SIZEFIRST, + SIZELAST = 17, + OBJECT = 19, + CLOSE, + HELP + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IApplicationDestinations.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IApplicationDestinations.cs new file mode 100644 index 00000000..1329ccaa --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IApplicationDestinations.cs @@ -0,0 +1,17 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("12337d35-94c6-48a0-bce7-6a9c69d4d600")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IApplicationDestinations + { + void SetAppID([MarshalAs(UnmanagedType.LPWStr)] [In] string pszAppID); + + void RemoveDestination([MarshalAs(UnmanagedType.IUnknown)] object punk); + + void RemoveAllDestinations(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IApplicationDocumentLists.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IApplicationDocumentLists.cs new file mode 100644 index 00000000..ac621afe --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IApplicationDocumentLists.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("3c594f9f-9f30-47a1-979a-c9e83d3d0a06")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IApplicationDocumentLists + { + void SetAppID([MarshalAs(UnmanagedType.LPWStr)] string pszAppID); + + [return: MarshalAs(UnmanagedType.IUnknown)] + object GetList([In] APPDOCLISTTYPE listtype, [In] uint cItemsDesired, [In] ref Guid riid); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/ICustomDestinationList.cs b/src/Shared/Microsoft.Windows.Shell/Standard/ICustomDestinationList.cs new file mode 100644 index 00000000..a371cbf6 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/ICustomDestinationList.cs @@ -0,0 +1,33 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("6332debf-87b5-4670-90c0-5e57b408a49e")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface ICustomDestinationList + { + void SetAppID([MarshalAs(UnmanagedType.LPWStr)] [In] string pszAppID); + + [return: MarshalAs(UnmanagedType.Interface)] + object BeginList(out uint pcMaxSlots, [In] ref Guid riid); + + [PreserveSig] + HRESULT AppendCategory([MarshalAs(UnmanagedType.LPWStr)] string pszCategory, IObjectArray poa); + + void AppendKnownCategory(KDC category); + + [PreserveSig] + HRESULT AddUserTasks(IObjectArray poa); + + void CommitList(); + + [return: MarshalAs(UnmanagedType.Interface)] + object GetRemovedDestinations([In] ref Guid riid); + + void DeleteList([MarshalAs(UnmanagedType.LPWStr)] string pszAppID); + + void AbortList(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IEnumIDList.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IEnumIDList.cs new file mode 100644 index 00000000..33955da2 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IEnumIDList.cs @@ -0,0 +1,21 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("000214F2-0000-0000-C000-000000000046")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IEnumIDList + { + [PreserveSig] + HRESULT Next(uint celt, out IntPtr rgelt, out int pceltFetched); + + [PreserveSig] + HRESULT Skip(uint celt); + + void Reset(); + + void Clone([MarshalAs(UnmanagedType.Interface)] out IEnumIDList ppenum); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IEnumObjects.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IEnumObjects.cs new file mode 100644 index 00000000..990f93e3 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IEnumObjects.cs @@ -0,0 +1,19 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("2c1c7e2e-2d0e-4059-831e-1e6f82335c2e")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IEnumObjects + { + void Next(uint celt, [In] ref Guid riid, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.IUnknown, SizeParamIndex = 0)] [Out] object[] rgelt, out uint pceltFetched); + + void Skip(uint celt); + + void Reset(); + + IEnumObjects Clone(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IID.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IID.cs new file mode 100644 index 00000000..266ef449 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IID.cs @@ -0,0 +1,55 @@ +using System; + +namespace Standard +{ + internal static class IID + { + public const string EnumIdList = "000214F2-0000-0000-C000-000000000046"; + + public const string EnumObjects = "2c1c7e2e-2d0e-4059-831e-1e6f82335c2e"; + + public const string HtmlDocument2 = "332C4425-26CB-11D0-B483-00C04FD90119"; + + public const string ModalWindow = "b4db1657-70d7-485e-8e3e-6fcb5a5c1802"; + + public const string ObjectArray = "92CA9DCD-5622-4bba-A805-5E9F541BD8C9"; + + public const string ObjectCollection = "5632b1a4-e38a-400a-928a-d4cd63230295"; + + public const string PropertyNotifySink = "9BFBBC02-EFF1-101A-84ED-00AA00341D07"; + + public const string PropertyStore = "886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"; + + public const string ServiceProvider = "6d5140c1-7436-11ce-8034-00aa006009fa"; + + public const string ShellFolder = "000214E6-0000-0000-C000-000000000046"; + + public const string ShellLink = "000214F9-0000-0000-C000-000000000046"; + + public const string ShellItem = "43826d1e-e718-42ee-bc55-a1e261c37bfe"; + + public const string ShellItem2 = "7e9fb0d3-919f-4307-ab2e-9b1860310c93"; + + public const string ShellItemArray = "B63EA76D-1F85-456F-A19C-48159EFA858B"; + + public const string TaskbarList = "56FDF342-FD6D-11d0-958A-006097C9A090"; + + public const string TaskbarList2 = "602D4995-B13A-429b-A66E-1935E44F4317"; + + public const string Unknown = "00000000-0000-0000-C000-000000000046"; + + public const string ApplicationDestinations = "12337d35-94c6-48a0-bce7-6a9c69d4d600"; + + public const string ApplicationDocumentLists = "3c594f9f-9f30-47a1-979a-c9e83d3d0a06"; + + public const string CustomDestinationList = "6332debf-87b5-4670-90c0-5e57b408a49e"; + + public const string ObjectWithAppUserModelId = "36db0196-9665-46d1-9ba7-d3709eecf9ed"; + + public const string ObjectWithProgId = "71e806fb-8dee-46fc-bf8c-7748a8a1ae13"; + + public const string TaskbarList3 = "ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf"; + + public const string TaskbarList4 = "c43dc798-95d1-4bea-9030-bb99e2983a1a"; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/INPUT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/INPUT.cs new file mode 100644 index 00000000..7bd8793a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/INPUT.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal struct INPUT + { + public uint type; + + public MOUSEINPUT mi; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/INPUT_TYPE.cs b/src/Shared/Microsoft.Windows.Shell/Standard/INPUT_TYPE.cs new file mode 100644 index 00000000..7ada551a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/INPUT_TYPE.cs @@ -0,0 +1,9 @@ +using System; + +namespace Standard +{ + internal enum INPUT_TYPE : uint + { + MOUSE + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IObjectArray.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IObjectArray.cs new file mode 100644 index 00000000..d084511f --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IObjectArray.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9")] + [ComImport] + internal interface IObjectArray + { + uint GetCount(); + + [return: MarshalAs(UnmanagedType.IUnknown)] + object GetAt([In] uint uiIndex, [In] ref Guid riid); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IObjectCollection.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IObjectCollection.cs new file mode 100644 index 00000000..6f3b672e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IObjectCollection.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9")] + [ComImport] + internal interface IObjectCollection : IObjectArray + { + uint GetCount(); + + [return: MarshalAs(UnmanagedType.IUnknown)] + object GetAt([In] uint uiIndex, [In] ref Guid riid); + + void AddObject([MarshalAs(UnmanagedType.IUnknown)] object punk); + + void AddFromArray(IObjectArray poaSource); + + void RemoveObjectAt(uint uiIndex); + + void Clear(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IObjectWithAppUserModelId.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IObjectWithAppUserModelId.cs new file mode 100644 index 00000000..a605067e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IObjectWithAppUserModelId.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("36db0196-9665-46d1-9ba7-d3709eecf9ed")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IObjectWithAppUserModelId + { + void SetAppID([MarshalAs(UnmanagedType.LPWStr)] string pszAppID); + + [return: MarshalAs(UnmanagedType.LPWStr)] + string GetAppID(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IObjectWithProgId.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IObjectWithProgId.cs new file mode 100644 index 00000000..4433dce3 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IObjectWithProgId.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("71e806fb-8dee-46fc-bf8c-7748a8a1ae13")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IObjectWithProgId + { + void SetProgID([MarshalAs(UnmanagedType.LPWStr)] string pszProgID); + + [return: MarshalAs(UnmanagedType.LPWStr)] + string GetProgID(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IPropertyStore.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IPropertyStore.cs new file mode 100644 index 00000000..6f8a7c26 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IPropertyStore.cs @@ -0,0 +1,21 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IPropertyStore + { + uint GetCount(); + + PKEY GetAt(uint iProp); + + void GetValue([In] ref PKEY pkey, [In] [Out] PROPVARIANT pv); + + void SetValue([In] ref PKEY pkey, PROPVARIANT pv); + + void Commit(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IShellFolder.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IShellFolder.cs new file mode 100644 index 00000000..833ef135 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IShellFolder.cs @@ -0,0 +1,37 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +namespace Standard +{ + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214E6-0000-0000-C000-000000000046")] + [ComImport] + internal interface IShellFolder + { + void ParseDisplayName([In] IntPtr hwnd, [In] IBindCtx pbc, [MarshalAs(UnmanagedType.LPWStr)] [In] string pszDisplayName, [In] [Out] ref int pchEaten, out IntPtr ppidl, [In] [Out] ref uint pdwAttributes); + + IEnumIDList EnumObjects([In] IntPtr hwnd, [In] SHCONTF grfFlags); + + [return: MarshalAs(UnmanagedType.Interface)] + object BindToObject([In] IntPtr pidl, [In] IBindCtx pbc, [In] ref Guid riid); + + [return: MarshalAs(UnmanagedType.Interface)] + object BindToStorage([In] IntPtr pidl, [In] IBindCtx pbc, [In] ref Guid riid); + + [PreserveSig] + HRESULT CompareIDs([In] IntPtr lParam, [In] IntPtr pidl1, [In] IntPtr pidl2); + + [return: MarshalAs(UnmanagedType.Interface)] + object CreateViewObject([In] IntPtr hwndOwner, [In] ref Guid riid); + + void GetAttributesOf([In] uint cidl, [In] IntPtr apidl, [In] [Out] ref SFGAO rgfInOut); + + [return: MarshalAs(UnmanagedType.Interface)] + object GetUIObjectOf([In] IntPtr hwndOwner, [In] uint cidl, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.SysInt, SizeParamIndex = 2)] [In] IntPtr apidl, [In] ref Guid riid, [In] [Out] ref uint rgfReserved); + + void GetDisplayNameOf([In] IntPtr pidl, [In] SHGDN uFlags, out IntPtr pName); + + void SetNameOf([In] IntPtr hwnd, [In] IntPtr pidl, [MarshalAs(UnmanagedType.LPWStr)] [In] string pszName, [In] SHGDN uFlags, out IntPtr ppidlOut); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IShellItem.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IShellItem.cs new file mode 100644 index 00000000..38ffae6a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IShellItem.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +namespace Standard +{ + [Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IShellItem + { + [return: MarshalAs(UnmanagedType.Interface)] + object BindToHandler(IBindCtx pbc, [In] ref Guid bhid, [In] ref Guid riid); + + IShellItem GetParent(); + + [return: MarshalAs(UnmanagedType.LPWStr)] + string GetDisplayName(SIGDN sigdnName); + + SFGAO GetAttributes(SFGAO sfgaoMask); + + int Compare(IShellItem psi, SICHINT hint); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IShellItem2.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IShellItem2.cs new file mode 100644 index 00000000..dc87db2e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IShellItem2.cs @@ -0,0 +1,56 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +namespace Standard +{ + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("7e9fb0d3-919f-4307-ab2e-9b1860310c93")] + [ComImport] + internal interface IShellItem2 : IShellItem + { + [return: MarshalAs(UnmanagedType.Interface)] + object BindToHandler([In] IBindCtx pbc, [In] ref Guid bhid, [In] ref Guid riid); + + IShellItem GetParent(); + + [return: MarshalAs(UnmanagedType.LPWStr)] + string GetDisplayName(SIGDN sigdnName); + + SFGAO GetAttributes(SFGAO sfgaoMask); + + int Compare(IShellItem psi, SICHINT hint); + + [return: MarshalAs(UnmanagedType.Interface)] + object GetPropertyStore(GPS flags, [In] ref Guid riid); + + [return: MarshalAs(UnmanagedType.Interface)] + object GetPropertyStoreWithCreateObject(GPS flags, [MarshalAs(UnmanagedType.IUnknown)] object punkCreateObject, [In] ref Guid riid); + + [return: MarshalAs(UnmanagedType.Interface)] + object GetPropertyStoreForKeys(IntPtr rgKeys, uint cKeys, GPS flags, [In] ref Guid riid); + + [return: MarshalAs(UnmanagedType.Interface)] + object GetPropertyDescriptionList(IntPtr keyType, [In] ref Guid riid); + + void Update(IBindCtx pbc); + + PROPVARIANT GetProperty(IntPtr key); + + Guid GetCLSID(IntPtr key); + + System.Runtime.InteropServices.ComTypes.FILETIME GetFileTime(IntPtr key); + + int GetInt32(IntPtr key); + + [return: MarshalAs(UnmanagedType.LPWStr)] + string GetString(IntPtr key); + + uint GetUInt32(IntPtr key); + + ulong GetUInt64(IntPtr key); + + [return: MarshalAs(UnmanagedType.Bool)] + void GetBool(IntPtr key); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IShellItemArray.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IShellItemArray.cs new file mode 100644 index 00000000..3d9950b8 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IShellItemArray.cs @@ -0,0 +1,30 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +namespace Standard +{ + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("B63EA76D-1F85-456F-A19C-48159EFA858B")] + [ComImport] + internal interface IShellItemArray + { + [return: MarshalAs(UnmanagedType.Interface)] + object BindToHandler(IBindCtx pbc, [In] ref Guid rbhid, [In] ref Guid riid); + + [return: MarshalAs(UnmanagedType.Interface)] + object GetPropertyStore(int flags, [In] ref Guid riid); + + [return: MarshalAs(UnmanagedType.Interface)] + object GetPropertyDescriptionList([In] ref PKEY keyType, [In] ref Guid riid); + + uint GetAttributes(SIATTRIBFLAGS dwAttribFlags, uint sfgaoMask); + + uint GetCount(); + + IShellItem GetItemAt(uint dwIndex); + + [return: MarshalAs(UnmanagedType.Interface)] + object EnumItems(); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/IShellLinkW.cs b/src/Shared/Microsoft.Windows.Shell/Standard/IShellLinkW.cs new file mode 100644 index 00000000..a2c558c5 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/IShellLinkW.cs @@ -0,0 +1,48 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +namespace Standard +{ + [Guid("000214F9-0000-0000-C000-000000000046")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface IShellLinkW + { + void GetPath([MarshalAs(UnmanagedType.LPWStr)] [Out] StringBuilder pszFile, int cchMaxPath, [In] [Out] WIN32_FIND_DATAW pfd, SLGP 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); + + short GetHotKey(); + + void SetHotKey(short wHotKey); + + uint GetShowCmd(); + + void SetShowCmd(uint iShowCmd); + + void GetIconLocation([MarshalAs(UnmanagedType.LPWStr)] [Out] StringBuilder pszIconPath, int cchIconPath, out int piIcon); + + 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); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList.cs b/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList.cs new file mode 100644 index 00000000..5fc0e132 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList.cs @@ -0,0 +1,21 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("56FDF342-FD6D-11d0-958A-006097C9A090")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface ITaskbarList + { + void HrInit(); + + void AddTab(IntPtr hwnd); + + void DeleteTab(IntPtr hwnd); + + void ActivateTab(IntPtr hwnd); + + void SetActiveAlt(IntPtr hwnd); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList2.cs b/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList2.cs new file mode 100644 index 00000000..2c761c46 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList2.cs @@ -0,0 +1,23 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("602D4995-B13A-429b-A66E-1935E44F4317")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface ITaskbarList2 : ITaskbarList + { + 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); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList3.cs b/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList3.cs new file mode 100644 index 00000000..d824fb5e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList3.cs @@ -0,0 +1,59 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [ComImport] + internal interface ITaskbarList3 : ITaskbarList2, ITaskbarList + { + 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); + + [PreserveSig] + HRESULT SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal); + + [PreserveSig] + HRESULT SetProgressState(IntPtr hwnd, TBPF tbpFlags); + + [PreserveSig] + HRESULT RegisterTab(IntPtr hwndTab, IntPtr hwndMDI); + + [PreserveSig] + HRESULT UnregisterTab(IntPtr hwndTab); + + [PreserveSig] + HRESULT SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore); + + [PreserveSig] + HRESULT SetTabActive(IntPtr hwndTab, IntPtr hwndMDI, uint dwReserved); + + [PreserveSig] + HRESULT ThumbBarAddButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] THUMBBUTTON[] pButtons); + + [PreserveSig] + HRESULT ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] THUMBBUTTON[] pButtons); + + [PreserveSig] + HRESULT ThumbBarSetImageList(IntPtr hwnd, [MarshalAs(UnmanagedType.IUnknown)] object himl); + + [PreserveSig] + HRESULT SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string pszDescription); + + [PreserveSig] + HRESULT SetThumbnailTooltip(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszTip); + + [PreserveSig] + HRESULT SetThumbnailClip(IntPtr hwnd, RefRECT prcClip); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList4.cs b/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList4.cs new file mode 100644 index 00000000..0c70461c --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/ITaskbarList4.cs @@ -0,0 +1,61 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")] + [ComImport] + internal interface ITaskbarList4 : ITaskbarList3, ITaskbarList2, ITaskbarList + { + 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); + + [PreserveSig] + HRESULT SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal); + + [PreserveSig] + HRESULT SetProgressState(IntPtr hwnd, TBPF tbpFlags); + + [PreserveSig] + HRESULT RegisterTab(IntPtr hwndTab, IntPtr hwndMDI); + + [PreserveSig] + HRESULT UnregisterTab(IntPtr hwndTab); + + [PreserveSig] + HRESULT SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore); + + [PreserveSig] + HRESULT SetTabActive(IntPtr hwndTab, IntPtr hwndMDI, uint dwReserved); + + [PreserveSig] + HRESULT ThumbBarAddButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] THUMBBUTTON[] pButtons); + + [PreserveSig] + HRESULT ThumbBarUpdateButtons(IntPtr hwnd, uint cButtons, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] THUMBBUTTON[] pButtons); + + [PreserveSig] + HRESULT ThumbBarSetImageList(IntPtr hwnd, [MarshalAs(UnmanagedType.IUnknown)] object himl); + + [PreserveSig] + HRESULT SetOverlayIcon(IntPtr hwnd, IntPtr hIcon, [MarshalAs(UnmanagedType.LPWStr)] string pszDescription); + + [PreserveSig] + HRESULT SetThumbnailTooltip(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszTip); + + [PreserveSig] + HRESULT SetThumbnailClip(IntPtr hwnd, RefRECT prcClip); + + void SetTabProperties(IntPtr hwndTab, STPF stpFlags); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/KDC.cs b/src/Shared/Microsoft.Windows.Shell/Standard/KDC.cs new file mode 100644 index 00000000..c98347f5 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/KDC.cs @@ -0,0 +1,10 @@ +using System; + +namespace Standard +{ + internal enum KDC + { + FREQUENT = 1, + RECENT + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/LOGFONT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/LOGFONT.cs new file mode 100644 index 00000000..17234be0 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/LOGFONT.cs @@ -0,0 +1,38 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + internal struct LOGFONT + { + public int lfHeight; + + public int lfWidth; + + public int lfEscapement; + + public int lfOrientation; + + public int lfWeight; + + public byte lfItalic; + + public byte lfUnderline; + + public byte lfStrikeOut; + + public byte lfCharSet; + + public byte lfOutPrecision; + + public byte lfClipPrecision; + + public byte lfQuality; + + public byte lfPitchAndFamily; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string lfFaceName; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MARGINS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MARGINS.cs new file mode 100644 index 00000000..db134daa --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MARGINS.cs @@ -0,0 +1,15 @@ +using System; + +namespace Standard +{ + internal struct MARGINS + { + public int cxLeftWidth; + + public int cxRightWidth; + + public int cyTopHeight; + + public int cyBottomHeight; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MF.cs new file mode 100644 index 00000000..374087f0 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MF.cs @@ -0,0 +1,14 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum MF : uint + { + DOES_NOT_EXIST = 4294967295u, + ENABLED = 0u, + BYCOMMAND = 0u, + GRAYED = 1u, + DISABLED = 2u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MINMAXINFO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MINMAXINFO.cs new file mode 100644 index 00000000..eba1b7b7 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MINMAXINFO.cs @@ -0,0 +1,17 @@ +using System; + +namespace Standard +{ + internal struct MINMAXINFO + { + public POINT ptReserved; + + public POINT ptMaxSize; + + public POINT ptMaxPosition; + + public POINT ptMinTrackSize; + + public POINT ptMaxTrackSize; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MONITORINFO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MONITORINFO.cs new file mode 100644 index 00000000..31c8813e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MONITORINFO.cs @@ -0,0 +1,17 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential)] + internal class MONITORINFO + { + public int cbSize = Marshal.SizeOf(typeof(MONITORINFO)); + + public RECT rcMonitor; + + public RECT rcWork; + + public int dwFlags; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MOUSEEVENTF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MOUSEEVENTF.cs new file mode 100644 index 00000000..37d98db6 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MOUSEEVENTF.cs @@ -0,0 +1,10 @@ +using System; + +namespace Standard +{ + internal enum MOUSEEVENTF + { + LEFTDOWN = 2, + LEFTUP = 4 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MOUSEINPUT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MOUSEINPUT.cs new file mode 100644 index 00000000..70bfc8ea --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MOUSEINPUT.cs @@ -0,0 +1,19 @@ +using System; + +namespace Standard +{ + internal struct MOUSEINPUT + { + public int dx; + + public int dy; + + public int mouseData; + + public int dwFlags; + + public int time; + + public IntPtr dwExtraInfo; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MSGFLT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MSGFLT.cs new file mode 100644 index 00000000..39ca35c8 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MSGFLT.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal enum MSGFLT + { + RESET, + ALLOW, + DISALLOW + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MSGFLTINFO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MSGFLTINFO.cs new file mode 100644 index 00000000..cc91b3ef --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MSGFLTINFO.cs @@ -0,0 +1,12 @@ +using System; + +namespace Standard +{ + internal enum MSGFLTINFO + { + NONE, + ALREADYALLOWED_FORWND, + ALREADYDISALLOWED_FORWND, + ALLOWED_HIGHER + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/ManagedIStream.cs b/src/Shared/Microsoft.Windows.Shell/Standard/ManagedIStream.cs new file mode 100644 index 00000000..7b897cbd --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/ManagedIStream.cs @@ -0,0 +1,150 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +namespace Standard +{ + internal sealed class ManagedIStream : IStream, IDisposable + { + public ManagedIStream(Stream source) + { + Verify.IsNotNull(source, "source"); + this._source = source; + } + + private void _Validate() + { + if (this._source == null) + { + throw new ObjectDisposedException("this"); + } + } + + [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Standard.HRESULT.ThrowIfFailed(System.String)")] + [Obsolete("The method is not implemented", true)] + public void Clone(out IStream ppstm) + { + ppstm = null; + HRESULT.STG_E_INVALIDFUNCTION.ThrowIfFailed("The method is not implemented."); + } + + public void Commit(int grfCommitFlags) + { + this._Validate(); + this._source.Flush(); + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] + public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten) + { + Verify.IsNotNull(pstm, "pstm"); + this._Validate(); + byte[] array = new byte[4096]; + long num; + int num2; + for (num = 0L; num < cb; num += (long)num2) + { + num2 = this._source.Read(array, 0, array.Length); + if (num2 == 0) + { + break; + } + pstm.Write(array, num2, IntPtr.Zero); + } + if (IntPtr.Zero != pcbRead) + { + Marshal.WriteInt64(pcbRead, num); + } + if (IntPtr.Zero != pcbWritten) + { + Marshal.WriteInt64(pcbWritten, num); + } + } + + [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Standard.HRESULT.ThrowIfFailed(System.String)")] + [Obsolete("The method is not implemented", true)] + public void LockRegion(long libOffset, long cb, int dwLockType) + { + HRESULT.STG_E_INVALIDFUNCTION.ThrowIfFailed("The method is not implemented."); + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public void Read(byte[] pv, int cb, IntPtr pcbRead) + { + this._Validate(); + int val = this._source.Read(pv, 0, cb); + if (IntPtr.Zero != pcbRead) + { + Marshal.WriteInt32(pcbRead, val); + } + } + + [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Standard.HRESULT.ThrowIfFailed(System.String)")] + [Obsolete("The method is not implemented", true)] + public void Revert() + { + HRESULT.STG_E_INVALIDFUNCTION.ThrowIfFailed("The method is not implemented."); + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public void Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition) + { + this._Validate(); + long val = this._source.Seek(dlibMove, (SeekOrigin)dwOrigin); + if (IntPtr.Zero != plibNewPosition) + { + Marshal.WriteInt64(plibNewPosition, val); + } + } + + public void SetSize(long libNewSize) + { + this._Validate(); + this._source.SetLength(libNewSize); + } + + public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, int grfStatFlag) + { + pstatstg = default(System.Runtime.InteropServices.ComTypes.STATSTG); + this._Validate(); + pstatstg.type = 2; + pstatstg.cbSize = this._source.Length; + pstatstg.grfMode = 2; + pstatstg.grfLocksSupported = 2; + } + + [Obsolete("The method is not implemented", true)] + [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Standard.HRESULT.ThrowIfFailed(System.String)")] + public void UnlockRegion(long libOffset, long cb, int dwLockType) + { + HRESULT.STG_E_INVALIDFUNCTION.ThrowIfFailed("The method is not implemented."); + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public void Write(byte[] pv, int cb, IntPtr pcbWritten) + { + this._Validate(); + this._source.Write(pv, 0, cb); + if (IntPtr.Zero != pcbWritten) + { + Marshal.WriteInt32(pcbWritten, cb); + } + } + + public void Dispose() + { + this._source = null; + } + + private const int STGTY_STREAM = 2; + + private const int STGM_READWRITE = 2; + + private const int LOCK_EXCLUSIVE = 2; + + private Stream _source; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MessageHandler.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MessageHandler.cs new file mode 100644 index 00000000..b3fee3f4 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MessageHandler.cs @@ -0,0 +1,6 @@ +using System; + +namespace Standard +{ + internal delegate IntPtr MessageHandler(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled); +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/MessageWindow.cs b/src/Shared/Microsoft.Windows.Shell/Standard/MessageWindow.cs new file mode 100644 index 00000000..30f7bad7 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/MessageWindow.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Threading; + +namespace Standard +{ + internal sealed class MessageWindow : DispatcherObject, IDisposable + { + public IntPtr Handle { get; private set; } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public MessageWindow(CS classStyle, WS style, WS_EX exStyle, Rect location, string name, WndProc callback) + { + this._wndProcCallback = callback; + this._className = "MessageWindowClass+" + Guid.NewGuid().ToString(); + WNDCLASSEX wndclassex = new WNDCLASSEX + { + cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)), + style = classStyle, + lpfnWndProc = MessageWindow.s_WndProc, + hInstance = NativeMethods.GetModuleHandle(null), + hbrBackground = NativeMethods.GetStockObject(StockObject.NULL_BRUSH), + lpszMenuName = "", + lpszClassName = this._className + }; + NativeMethods.RegisterClassEx(ref wndclassex); + GCHandle value = default(GCHandle); + try + { + value = GCHandle.Alloc(this); + IntPtr lpParam = (IntPtr)value; + this.Handle = NativeMethods.CreateWindowEx(exStyle, this._className, name, style, (int)location.X, (int)location.Y, (int)location.Width, (int)location.Height, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, lpParam); + } + finally + { + value.Free(); + } + } + + ~MessageWindow() + { + this._Dispose(false, false); + } + + public void Dispose() + { + this._Dispose(true, false); + GC.SuppressFinalize(this); + } + + [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "disposing")] + private void _Dispose(bool disposing, bool isHwndBeingDestroyed) + { + if (this._isDisposed) + { + return; + } + this._isDisposed = true; + IntPtr hwnd = this.Handle; + string className = this._className; + if (isHwndBeingDestroyed) + { + base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback((object arg) => MessageWindow._DestroyWindow(IntPtr.Zero, className))); + } + else if (this.Handle != IntPtr.Zero) + { + if (base.CheckAccess()) + { + MessageWindow._DestroyWindow(hwnd, className); + } + else + { + base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback((object arg) => MessageWindow._DestroyWindow(hwnd, className))); + } + } + MessageWindow.s_windowLookup.Remove(hwnd); + this._className = null; + this.Handle = IntPtr.Zero; + } + + [SuppressMessage("Microsoft.Usage", "CA1816:CallGCSuppressFinalizeCorrectly")] + private static IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam) + { + IntPtr result = IntPtr.Zero; + MessageWindow messageWindow = null; + if (msg == WM.CREATE) + { + messageWindow = (MessageWindow)GCHandle.FromIntPtr(((CREATESTRUCT)Marshal.PtrToStructure(lParam, typeof(CREATESTRUCT))).lpCreateParams).Target; + MessageWindow.s_windowLookup.Add(hwnd, messageWindow); + } + else if (!MessageWindow.s_windowLookup.TryGetValue(hwnd, out messageWindow)) + { + return NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam); + } + WndProc wndProcCallback = messageWindow._wndProcCallback; + if (wndProcCallback != null) + { + result = wndProcCallback(hwnd, msg, wParam, lParam); + } + else + { + result = NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam); + } + if (msg == WM.NCDESTROY) + { + messageWindow._Dispose(true, true); + GC.SuppressFinalize(messageWindow); + } + return result; + } + + private static object _DestroyWindow(IntPtr hwnd, string className) + { + Utility.SafeDestroyWindow(ref hwnd); + NativeMethods.UnregisterClass(className, NativeMethods.GetModuleHandle(null)); + return null; + } + + private static readonly WndProc s_WndProc = new WndProc(MessageWindow._WndProc); + + private static readonly Dictionary s_windowLookup = new Dictionary(); + + private WndProc _wndProcCallback; + + private string _className; + + private bool _isDisposed; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/NIF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/NIF.cs new file mode 100644 index 00000000..d4c306a0 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/NIF.cs @@ -0,0 +1,19 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum NIF : uint + { + MESSAGE = 1u, + ICON = 2u, + TIP = 4u, + STATE = 8u, + INFO = 16u, + GUID = 32u, + REALTIME = 64u, + SHOWTIP = 128u, + XP_MASK = 59u, + VISTA_MASK = 251u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/NIIF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/NIIF.cs new file mode 100644 index 00000000..3231c2cc --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/NIIF.cs @@ -0,0 +1,17 @@ +using System; + +namespace Standard +{ + internal enum NIIF + { + NONE, + INFO, + WARNING, + ERROR, + USER, + NOSOUND = 16, + LARGE_ICON = 32, + NIIF_RESPECT_QUIET_TIME = 128, + XP_ICON_MASK = 15 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/NIM.cs b/src/Shared/Microsoft.Windows.Shell/Standard/NIM.cs new file mode 100644 index 00000000..84a09864 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/NIM.cs @@ -0,0 +1,13 @@ +using System; + +namespace Standard +{ + internal enum NIM : uint + { + ADD, + MODIFY, + DELETE, + SETFOCUS, + SETVERSION + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/NONCLIENTMETRICS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/NONCLIENTMETRICS.cs new file mode 100644 index 00000000..a5f23a06 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/NONCLIENTMETRICS.cs @@ -0,0 +1,65 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + internal struct NONCLIENTMETRICS + { + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public static NONCLIENTMETRICS VistaMetricsStruct + { + get + { + return new NONCLIENTMETRICS + { + cbSize = Marshal.SizeOf(typeof(NONCLIENTMETRICS)) + }; + } + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public static NONCLIENTMETRICS XPMetricsStruct + { + get + { + return new NONCLIENTMETRICS + { + cbSize = Marshal.SizeOf(typeof(NONCLIENTMETRICS)) - 4 + }; + } + } + + public int cbSize; + + public int iBorderWidth; + + public int iScrollWidth; + + public int iScrollHeight; + + public int iCaptionWidth; + + public int iCaptionHeight; + + public LOGFONT lfCaptionFont; + + public int iSmCaptionWidth; + + public int iSmCaptionHeight; + + public LOGFONT lfSmCaptionFont; + + public int iMenuWidth; + + public int iMenuHeight; + + public LOGFONT lfMenuFont; + + public LOGFONT lfStatusFont; + + public LOGFONT lfMessageFont; + + public int iPaddedBorderWidth; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/NOTIFYICONDATA.cs b/src/Shared/Microsoft.Windows.Shell/Standard/NOTIFYICONDATA.cs new file mode 100644 index 00000000..4ff9665b --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/NOTIFYICONDATA.cs @@ -0,0 +1,44 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")] + [StructLayout(LayoutKind.Sequential)] + internal class NOTIFYICONDATA + { + public int cbSize; + + public IntPtr hWnd; + + public int uID; + + public NIF uFlags; + + public int uCallbackMessage; + + public IntPtr hIcon; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] + public char[] szTip = new char[128]; + + public uint dwState; + + public uint dwStateMask; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] + public char[] szInfo = new char[256]; + + public uint uVersion; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] + public char[] szInfoTitle = new char[64]; + + public uint dwInfoFlags; + + public Guid guidItem; + + private IntPtr hBalloonIcon; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/NativeMethods.cs b/src/Shared/Microsoft.Windows.Shell/Standard/NativeMethods.cs new file mode 100644 index 00000000..746cc7be --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/NativeMethods.cs @@ -0,0 +1,908 @@ +using System; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.ConstrainedExecution; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using System.Text; + +namespace Standard +{ + internal static class NativeMethods + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "AdjustWindowRectEx", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _AdjustWindowRectEx(ref RECT lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle); + + public static RECT AdjustWindowRectEx(RECT lpRect, WS dwStyle, bool bMenu, WS_EX dwExStyle) + { + if (!NativeMethods._AdjustWindowRectEx(ref lpRect, dwStyle, bMenu, dwExStyle)) + { + HRESULT.ThrowLastError(); + } + return lpRect; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "ChangeWindowMessageFilter", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _ChangeWindowMessageFilter(WM message, MSGFLT dwFlag); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "ChangeWindowMessageFilterEx", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _ChangeWindowMessageFilterEx(IntPtr hwnd, WM message, MSGFLT action, [In] [Out] ref CHANGEFILTERSTRUCT pChangeFilterStruct); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static HRESULT ChangeWindowMessageFilterEx(IntPtr hwnd, WM message, MSGFLT action, out MSGFLTINFO filterInfo) + { + filterInfo = MSGFLTINFO.NONE; + if (!Utility.IsOSVistaOrNewer) + { + return HRESULT.S_FALSE; + } + if (!Utility.IsOSWindows7OrNewer) + { + if (!NativeMethods._ChangeWindowMessageFilter(message, action)) + { + return (HRESULT)Win32Error.GetLastError(); + } + return HRESULT.S_OK; + } + else + { + CHANGEFILTERSTRUCT changefilterstruct = new CHANGEFILTERSTRUCT + { + cbSize = (uint)Marshal.SizeOf(typeof(CHANGEFILTERSTRUCT)) + }; + if (!NativeMethods._ChangeWindowMessageFilterEx(hwnd, message, action, ref changefilterstruct)) + { + return (HRESULT)Win32Error.GetLastError(); + } + filterInfo = changefilterstruct.ExtStatus; + return HRESULT.S_OK; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll")] + public static extern CombineRgnResult CombineRgn(IntPtr hrgnDest, IntPtr hrgnSrc1, IntPtr hrgnSrc2, RGN fnCombineMode); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("shell32.dll", CharSet = CharSet.Unicode, EntryPoint = "CommandLineToArgvW")] + private static extern IntPtr _CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string cmdLine, out int numArgs); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static string[] CommandLineToArgvW(string cmdLine) + { + IntPtr intPtr = IntPtr.Zero; + string[] result; + try + { + int num = 0; + intPtr = NativeMethods._CommandLineToArgvW(cmdLine, out num); + if (intPtr == IntPtr.Zero) + { + throw new Win32Exception(); + } + string[] array = new string[num]; + for (int i = 0; i < num; i++) + { + IntPtr ptr = Marshal.ReadIntPtr(intPtr, i * Marshal.SizeOf(typeof(IntPtr))); + array[i] = Marshal.PtrToStringUni(ptr); + } + result = array; + } + finally + { + NativeMethods._LocalFree(intPtr); + } + return result; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", EntryPoint = "CreateDIBSection", SetLastError = true)] + private static extern SafeHBITMAP _CreateDIBSection(SafeDC hdc, [In] ref BITMAPINFO bitmapInfo, int iUsage, out IntPtr ppvBits, IntPtr hSection, int dwOffset); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", EntryPoint = "CreateDIBSection", SetLastError = true)] + private static extern SafeHBITMAP _CreateDIBSectionIntPtr(IntPtr hdc, [In] ref BITMAPINFO bitmapInfo, int iUsage, out IntPtr ppvBits, IntPtr hSection, int dwOffset); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static SafeHBITMAP CreateDIBSection(SafeDC hdc, ref BITMAPINFO bitmapInfo, out IntPtr ppvBits, IntPtr hSection, int dwOffset) + { + SafeHBITMAP safeHBITMAP; + if (hdc == null) + { + safeHBITMAP = NativeMethods._CreateDIBSectionIntPtr(IntPtr.Zero, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset); + } + else + { + safeHBITMAP = NativeMethods._CreateDIBSection(hdc, ref bitmapInfo, 0, out ppvBits, hSection, dwOffset); + } + if (safeHBITMAP.IsInvalid) + { + HRESULT.ThrowLastError(); + } + return safeHBITMAP; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", EntryPoint = "CreateRoundRectRgn", SetLastError = true)] + private static extern IntPtr _CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse) + { + IntPtr intPtr = NativeMethods._CreateRoundRectRgn(nLeftRect, nTopRect, nRightRect, nBottomRect, nWidthEllipse, nHeightEllipse); + if (IntPtr.Zero == intPtr) + { + throw new Win32Exception(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", EntryPoint = "CreateRectRgn", SetLastError = true)] + private static extern IntPtr _CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) + { + IntPtr intPtr = NativeMethods._CreateRectRgn(nLeftRect, nTopRect, nRightRect, nBottomRect); + if (IntPtr.Zero == intPtr) + { + throw new Win32Exception(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", EntryPoint = "CreateRectRgnIndirect", SetLastError = true)] + private static extern IntPtr _CreateRectRgnIndirect([In] ref RECT lprc); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr CreateRectRgnIndirect(RECT lprc) + { + IntPtr intPtr = NativeMethods._CreateRectRgnIndirect(ref lprc); + if (IntPtr.Zero == intPtr) + { + throw new Win32Exception(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll")] + public static extern IntPtr CreateSolidBrush(int crColor); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateWindowExW", SetLastError = true)] + private static extern IntPtr _CreateWindowEx(WS_EX dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr CreateWindowEx(WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam) + { + IntPtr intPtr = NativeMethods._CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); + if (IntPtr.Zero == intPtr) + { + HRESULT.ThrowLastError(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "DefWindowProcW")] + public static extern IntPtr DefWindowProc(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool DeleteObject(IntPtr hObject); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool DestroyIcon(IntPtr handle); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool DestroyWindow(IntPtr hwnd); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsWindow(IntPtr hwnd); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("dwmapi.dll", PreserveSig = false)] + public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("dwmapi.dll", EntryPoint = "DwmIsCompositionEnabled", PreserveSig = false)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _DwmIsCompositionEnabled(); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("dwmapi.dll", EntryPoint = "DwmGetColorizationColor")] + private static extern HRESULT _DwmGetColorizationColor(out uint pcrColorization, [MarshalAs(UnmanagedType.Bool)] out bool pfOpaqueBlend); + + public static bool DwmGetColorizationColor(out uint pcrColorization, out bool pfOpaqueBlend) + { + if (Utility.IsOSVistaOrNewer && NativeMethods.IsThemeActive() && NativeMethods._DwmGetColorizationColor(out pcrColorization, out pfOpaqueBlend).Succeeded) + { + return true; + } + pcrColorization = 4278190080u; + pfOpaqueBlend = true; + return false; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool DwmIsCompositionEnabled() + { + return Utility.IsOSVistaOrNewer && NativeMethods._DwmIsCompositionEnabled(); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("dwmapi.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool DwmDefWindowProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam, out IntPtr plResult); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("dwmapi.dll", EntryPoint = "DwmSetWindowAttribute")] + private static extern void _DwmSetWindowAttribute(IntPtr hwnd, DWMWA dwAttribute, ref int pvAttribute, int cbAttribute); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void DwmSetWindowAttributeFlip3DPolicy(IntPtr hwnd, DWMFLIP3D flip3dPolicy) + { + int num = (int)flip3dPolicy; + NativeMethods._DwmSetWindowAttribute(hwnd, DWMWA.FLIP3D_POLICY, ref num, 4); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void DwmSetWindowAttributeDisallowPeek(IntPtr hwnd, bool disallowPeek) + { + int num = disallowPeek ? 1 : 0; + NativeMethods._DwmSetWindowAttribute(hwnd, DWMWA.DISALLOW_PEEK, ref num, 4); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "EnableMenuItem")] + private static extern int _EnableMenuItem(IntPtr hMenu, SC uIDEnableItem, MF uEnable); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static MF EnableMenuItem(IntPtr hMenu, SC uIDEnableItem, MF uEnable) + { + return (MF)NativeMethods._EnableMenuItem(hMenu, uIDEnableItem, uEnable); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "RemoveMenu", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void RemoveMenu(IntPtr hMenu, SC uPosition, MF uFlags) + { + if (!NativeMethods._RemoveMenu(hMenu, (uint)uPosition, (uint)uFlags)) + { + throw new Win32Exception(); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "DrawMenuBar", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _DrawMenuBar(IntPtr hWnd); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void DrawMenuBar(IntPtr hWnd) + { + if (!NativeMethods._DrawMenuBar(hWnd)) + { + throw new Win32Exception(); + } + } + + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool FindClose(IntPtr handle); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + public static extern SafeFindHandle FindFirstFileW(string lpFileName, [MarshalAs(UnmanagedType.LPStruct)] [In] [Out] WIN32_FIND_DATAW lpFindFileData); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool FindNextFileW(SafeFindHandle hndFindFile, [MarshalAs(UnmanagedType.LPStruct)] [In] [Out] WIN32_FIND_DATAW lpFindFileData); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "GetClientRect", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _GetClientRect(IntPtr hwnd, out RECT lpRect); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static RECT GetClientRect(IntPtr hwnd) + { + RECT result; + if (!NativeMethods._GetClientRect(hwnd, out result)) + { + HRESULT.ThrowLastError(); + } + return result; + } + + [DllImport("uxtheme.dll", CharSet = CharSet.Unicode, EntryPoint = "GetCurrentThemeName")] + private static extern HRESULT _GetCurrentThemeName(StringBuilder pszThemeFileName, int dwMaxNameChars, StringBuilder pszColorBuff, int cchMaxColorChars, StringBuilder pszSizeBuff, int cchMaxSizeChars); + + public static void GetCurrentThemeName(out string themeFileName, out string color, out string size) + { + StringBuilder stringBuilder = new StringBuilder(260); + StringBuilder stringBuilder2 = new StringBuilder(260); + StringBuilder stringBuilder3 = new StringBuilder(260); + NativeMethods._GetCurrentThemeName(stringBuilder, stringBuilder.Capacity, stringBuilder2, stringBuilder2.Capacity, stringBuilder3, stringBuilder3.Capacity).ThrowIfFailed(); + themeFileName = stringBuilder.ToString(); + color = stringBuilder2.ToString(); + size = stringBuilder3.ToString(); + } + + [DllImport("uxtheme.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsThemeActive(); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [Obsolete("Use SafeDC.GetDC instead.", true)] + public static void GetDC() + { + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll")] + public static extern int GetDeviceCaps(SafeDC hdc, DeviceCap nIndex); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetModuleFileName", SetLastError = true)] + private static extern int _GetModuleFileName(IntPtr hModule, StringBuilder lpFilename, int nSize); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static string GetModuleFileName(IntPtr hModule) + { + StringBuilder stringBuilder = new StringBuilder(260); + for (;;) + { + int num = NativeMethods._GetModuleFileName(hModule, stringBuilder, stringBuilder.Capacity); + if (num == 0) + { + HRESULT.ThrowLastError(); + } + if (num != stringBuilder.Capacity) + { + break; + } + stringBuilder.EnsureCapacity(stringBuilder.Capacity * 2); + } + return stringBuilder.ToString(); + } + + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetModuleHandleW", SetLastError = true)] + private static extern IntPtr _GetModuleHandle([MarshalAs(UnmanagedType.LPWStr)] string lpModuleName); + + public static IntPtr GetModuleHandle(string lpModuleName) + { + IntPtr intPtr = NativeMethods._GetModuleHandle(lpModuleName); + if (intPtr == IntPtr.Zero) + { + HRESULT.ThrowLastError(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "GetMonitorInfo", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _GetMonitorInfo(IntPtr hMonitor, [In] [Out] MONITORINFO lpmi); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static MONITORINFO GetMonitorInfo(IntPtr hMonitor) + { + MONITORINFO monitorinfo = new MONITORINFO(); + if (!NativeMethods._GetMonitorInfo(hMonitor, monitorinfo)) + { + throw new Win32Exception(); + } + return monitorinfo; + } + + [DllImport("gdi32.dll", EntryPoint = "GetStockObject", SetLastError = true)] + private static extern IntPtr _GetStockObject(StockObject fnObject); + + public static IntPtr GetStockObject(StockObject fnObject) + { + return NativeMethods._GetStockObject(fnObject); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll")] + public static extern IntPtr GetSystemMenu(IntPtr hWnd, [MarshalAs(UnmanagedType.Bool)] bool bRevert); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll")] + public static extern int GetSystemMetrics(SM nIndex); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr GetWindowLongPtr(IntPtr hwnd, GWL nIndex) + { + IntPtr intPtr = IntPtr.Zero; + if (8 == IntPtr.Size) + { + intPtr = NativeMethods.GetWindowLongPtr64(hwnd, nIndex); + } + else + { + intPtr = new IntPtr(NativeMethods.GetWindowLongPtr32(hwnd, nIndex)); + } + if (IntPtr.Zero == intPtr) + { + throw new Win32Exception(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("uxtheme.dll", PreserveSig = false)] + public static extern void SetWindowThemeAttribute([In] IntPtr hwnd, [In] WINDOWTHEMEATTRIBUTETYPE eAttribute, [In] ref WTA_OPTIONS pvAttribute, [In] uint cbAttribute); + + [SuppressMessage("Microsoft.Interoperability", "CA1400:PInvokeEntryPointsShouldExist")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "GetWindowLong", SetLastError = true)] + private static extern int GetWindowLongPtr32(IntPtr hWnd, GWL nIndex); + + [SuppressMessage("Microsoft.Interoperability", "CA1400:PInvokeEntryPointsShouldExist")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", SetLastError = true)] + private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, GWL nIndex); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool GetWindowPlacement(IntPtr hwnd, WINDOWPLACEMENT lpwndpl); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static WINDOWPLACEMENT GetWindowPlacement(IntPtr hwnd) + { + WINDOWPLACEMENT windowplacement = new WINDOWPLACEMENT(); + if (NativeMethods.GetWindowPlacement(hwnd, windowplacement)) + { + return windowplacement; + } + throw new Win32Exception(); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "GetWindowRect", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _GetWindowRect(IntPtr hWnd, out RECT lpRect); + + public static RECT GetWindowRect(IntPtr hwnd) + { + RECT result; + if (!NativeMethods._GetWindowRect(hwnd, out result)) + { + HRESULT.ThrowLastError(); + } + return result; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdiplus.dll")] + public static extern Status GdipCreateBitmapFromStream(IStream stream, out IntPtr bitmap); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdiplus.dll")] + public static extern Status GdipCreateHBITMAPFromBitmap(IntPtr bitmap, out IntPtr hbmReturn, int background); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdiplus.dll")] + public static extern Status GdipCreateHICONFromBitmap(IntPtr bitmap, out IntPtr hbmReturn); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdiplus.dll")] + public static extern Status GdipDisposeImage(IntPtr image); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdiplus.dll")] + public static extern Status GdipImageForceValidation(IntPtr image); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdiplus.dll")] + public static extern Status GdiplusStartup(out IntPtr token, StartupInput input, out StartupOutput output); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdiplus.dll")] + public static extern Status GdiplusShutdown(IntPtr token); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsWindowVisible(IntPtr hwnd); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("kernel32.dll", EntryPoint = "LocalFree", SetLastError = true)] + private static extern IntPtr _LocalFree(IntPtr hMem); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll")] + public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "PostMessage", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _PostMessage(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void PostMessage(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam) + { + if (!NativeMethods._PostMessage(hWnd, Msg, wParam, lParam)) + { + throw new Win32Exception(); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "RegisterClassExW", SetLastError = true)] + private static extern short _RegisterClassEx([In] ref WNDCLASSEX lpwcx); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static short RegisterClassEx(ref WNDCLASSEX lpwcx) + { + short num = NativeMethods._RegisterClassEx(ref lpwcx); + if (num == 0) + { + HRESULT.ThrowLastError(); + } + return num; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegisterWindowMessage", SetLastError = true)] + private static extern uint _RegisterWindowMessage([MarshalAs(UnmanagedType.LPWStr)] string lpString); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static WM RegisterWindowMessage(string lpString) + { + uint num = NativeMethods._RegisterWindowMessage(lpString); + if (num == 0u) + { + HRESULT.ThrowLastError(); + } + return (WM)num; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "SetActiveWindow", SetLastError = true)] + private static extern IntPtr _SetActiveWindow(IntPtr hWnd); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr SetActiveWindow(IntPtr hwnd) + { + Verify.IsNotDefault(hwnd, "hwnd"); + IntPtr intPtr = NativeMethods._SetActiveWindow(hwnd); + if (intPtr == IntPtr.Zero) + { + HRESULT.ThrowLastError(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr SetClassLongPtr(IntPtr hwnd, GCLP nIndex, IntPtr dwNewLong) + { + if (8 == IntPtr.Size) + { + return NativeMethods.SetClassLongPtr64(hwnd, nIndex, dwNewLong); + } + return new IntPtr(NativeMethods.SetClassLongPtr32(hwnd, nIndex, dwNewLong.ToInt32())); + } + + [SuppressMessage("Microsoft.Interoperability", "CA1400:PInvokeEntryPointsShouldExist")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "SetClassLong", SetLastError = true)] + private static extern int SetClassLongPtr32(IntPtr hWnd, GCLP nIndex, int dwNewLong); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [SuppressMessage("Microsoft.Interoperability", "CA1400:PInvokeEntryPointsShouldExist")] + [DllImport("user32.dll", EntryPoint = "SetClassLongPtr", SetLastError = true)] + private static extern IntPtr SetClassLongPtr64(IntPtr hWnd, GCLP nIndex, IntPtr dwNewLong); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("kernel32.dll", SetLastError = true)] + public static extern ErrorModes SetErrorMode(ErrorModes newMode); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _SetProcessWorkingSetSize(IntPtr hProcess, IntPtr dwMinimiumWorkingSetSize, IntPtr dwMaximumWorkingSetSize); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SetProcessWorkingSetSize(IntPtr hProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize) + { + if (!NativeMethods._SetProcessWorkingSetSize(hProcess, new IntPtr(dwMinimumWorkingSetSize), new IntPtr(dwMaximumWorkingSetSize))) + { + throw new Win32Exception(); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr SetWindowLongPtr(IntPtr hwnd, GWL nIndex, IntPtr dwNewLong) + { + if (8 == IntPtr.Size) + { + return NativeMethods.SetWindowLongPtr64(hwnd, nIndex, dwNewLong); + } + return new IntPtr(NativeMethods.SetWindowLongPtr32(hwnd, nIndex, dwNewLong.ToInt32())); + } + + [SuppressMessage("Microsoft.Interoperability", "CA1400:PInvokeEntryPointsShouldExist")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)] + private static extern int SetWindowLongPtr32(IntPtr hWnd, GWL nIndex, int dwNewLong); + + [SuppressMessage("Microsoft.Interoperability", "CA1400:PInvokeEntryPointsShouldExist")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)] + private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, GWL nIndex, IntPtr dwNewLong); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "SetWindowRgn", SetLastError = true)] + private static extern int _SetWindowRgn(IntPtr hWnd, IntPtr hRgn, [MarshalAs(UnmanagedType.Bool)] bool bRedraw); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw) + { + if (NativeMethods._SetWindowRgn(hWnd, hRgn, bRedraw) == 0) + { + throw new Win32Exception(); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "SetWindowPos", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SWP uFlags); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SWP uFlags) + { + return NativeMethods._SetWindowPos(hWnd, hWndInsertAfter, x, y, cx, cy, uFlags); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("shell32.dll")] + public static extern Win32Error SHFileOperation(ref SHFILEOPSTRUCT lpFileOp); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool ShowWindow(IntPtr hwnd, SW nCmdShow); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "SystemParametersInfoW", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _SystemParametersInfo_String(SPI uiAction, int uiParam, [MarshalAs(UnmanagedType.LPWStr)] string pvParam, SPIF fWinIni); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "SystemParametersInfoW", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _SystemParametersInfo_NONCLIENTMETRICS(SPI uiAction, int uiParam, [In] [Out] ref NONCLIENTMETRICS pvParam, SPIF fWinIni); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "SystemParametersInfoW", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _SystemParametersInfo_HIGHCONTRAST(SPI uiAction, int uiParam, [In] [Out] ref HIGHCONTRAST pvParam, SPIF fWinIni); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SystemParametersInfo(SPI uiAction, int uiParam, string pvParam, SPIF fWinIni) + { + if (!NativeMethods._SystemParametersInfo_String(uiAction, uiParam, pvParam, fWinIni)) + { + HRESULT.ThrowLastError(); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static NONCLIENTMETRICS SystemParameterInfo_GetNONCLIENTMETRICS() + { + NONCLIENTMETRICS result = Utility.IsOSVistaOrNewer ? NONCLIENTMETRICS.VistaMetricsStruct : NONCLIENTMETRICS.XPMetricsStruct; + if (!NativeMethods._SystemParametersInfo_NONCLIENTMETRICS(SPI.GETNONCLIENTMETRICS, result.cbSize, ref result, SPIF.None)) + { + HRESULT.ThrowLastError(); + } + return result; + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public static HIGHCONTRAST SystemParameterInfo_GetHIGHCONTRAST() + { + HIGHCONTRAST result = new HIGHCONTRAST + { + cbSize = Marshal.SizeOf(typeof(HIGHCONTRAST)) + }; + if (!NativeMethods._SystemParametersInfo_HIGHCONTRAST(SPI.GETHIGHCONTRAST, result.cbSize, ref result, SPIF.None)) + { + HRESULT.ThrowLastError(); + } + return result; + } + + [DllImport("user32.dll")] + public static extern uint TrackPopupMenuEx(IntPtr hmenu, uint fuFlags, int x, int y, IntPtr hwnd, IntPtr lptpm); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", EntryPoint = "SelectObject", SetLastError = true)] + private static extern IntPtr _SelectObject(SafeDC hdc, IntPtr hgdiobj); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr SelectObject(SafeDC hdc, IntPtr hgdiobj) + { + IntPtr intPtr = NativeMethods._SelectObject(hdc, hgdiobj); + if (intPtr == IntPtr.Zero) + { + HRESULT.ThrowLastError(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", EntryPoint = "SelectObject", SetLastError = true)] + private static extern IntPtr _SelectObjectSafeHBITMAP(SafeDC hdc, SafeHBITMAP hgdiobj); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static IntPtr SelectObject(SafeDC hdc, SafeHBITMAP hgdiobj) + { + IntPtr intPtr = NativeMethods._SelectObjectSafeHBITMAP(hdc, hgdiobj); + if (intPtr == IntPtr.Zero) + { + HRESULT.ThrowLastError(); + } + return intPtr; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", SetLastError = true)] + public static extern int SendInput(int nInputs, ref INPUT pInputs, int cbSize); + + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr SendMessage(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "UnregisterClass", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _UnregisterClassAtom(IntPtr lpClassName, IntPtr hInstance); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "UnregisterClass", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _UnregisterClassName(string lpClassName, IntPtr hInstance); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void UnregisterClass(short atom, IntPtr hinstance) + { + if (!NativeMethods._UnregisterClassAtom(new IntPtr((int)atom), hinstance)) + { + HRESULT.ThrowLastError(); + } + } + + public static void UnregisterClass(string lpClassName, IntPtr hInstance) + { + if (!NativeMethods._UnregisterClassName(lpClassName, hInstance)) + { + HRESULT.ThrowLastError(); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "UpdateLayeredWindow", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _UpdateLayeredWindow(IntPtr hwnd, SafeDC hdcDst, [In] ref POINT pptDst, [In] ref SIZE psize, SafeDC hdcSrc, [In] ref POINT pptSrc, int crKey, ref BLENDFUNCTION pblend, ULW dwFlags); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll", EntryPoint = "UpdateLayeredWindow", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool _UpdateLayeredWindowIntPtr(IntPtr hwnd, IntPtr hdcDst, IntPtr pptDst, IntPtr psize, IntPtr hdcSrc, IntPtr pptSrc, int crKey, ref BLENDFUNCTION pblend, ULW dwFlags); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void UpdateLayeredWindow(IntPtr hwnd, SafeDC hdcDst, ref POINT pptDst, ref SIZE psize, SafeDC hdcSrc, ref POINT pptSrc, int crKey, ref BLENDFUNCTION pblend, ULW dwFlags) + { + if (!NativeMethods._UpdateLayeredWindow(hwnd, hdcDst, ref pptDst, ref psize, hdcSrc, ref pptSrc, crKey, ref pblend, dwFlags)) + { + HRESULT.ThrowLastError(); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void UpdateLayeredWindow(IntPtr hwnd, int crKey, ref BLENDFUNCTION pblend, ULW dwFlags) + { + if (!NativeMethods._UpdateLayeredWindowIntPtr(hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, crKey, ref pblend, dwFlags)) + { + HRESULT.ThrowLastError(); + } + } + + [DllImport("shell32.dll", EntryPoint = "SHAddToRecentDocs")] + private static extern void _SHAddToRecentDocs_String(SHARD uFlags, [MarshalAs(UnmanagedType.LPWStr)] string pv); + + [DllImport("shell32.dll", EntryPoint = "SHAddToRecentDocs")] + private static extern void _SHAddToRecentDocs_ShellLink(SHARD uFlags, IShellLinkW pv); + + public static void SHAddToRecentDocs(string path) + { + NativeMethods._SHAddToRecentDocs_String(SHARD.PATHW, path); + } + + public static void SHAddToRecentDocs(IShellLinkW shellLink) + { + NativeMethods._SHAddToRecentDocs_ShellLink(SHARD.LINK, shellLink); + } + + [DllImport("dwmapi.dll", EntryPoint = "DwmGetCompositionTimingInfo")] + private static extern HRESULT _DwmGetCompositionTimingInfo(IntPtr hwnd, ref DWM_TIMING_INFO pTimingInfo); + + public static DWM_TIMING_INFO? DwmGetCompositionTimingInfo(IntPtr hwnd) + { + if (!Utility.IsOSVistaOrNewer) + { + return null; + } + DWM_TIMING_INFO value = new DWM_TIMING_INFO + { + cbSize = Marshal.SizeOf(typeof(DWM_TIMING_INFO)) + }; + HRESULT hrLeft = NativeMethods._DwmGetCompositionTimingInfo(hwnd, ref value); + if (hrLeft == HRESULT.E_PENDING) + { + return null; + } + hrLeft.ThrowIfFailed(); + return new DWM_TIMING_INFO?(value); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("dwmapi.dll", PreserveSig = false)] + public static extern void DwmInvalidateIconicBitmaps(IntPtr hwnd); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("dwmapi.dll", PreserveSig = false)] + public static extern void DwmSetIconicThumbnail(IntPtr hwnd, IntPtr hbmp, DWM_SIT dwSITFlags); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("dwmapi.dll", PreserveSig = false)] + public static extern void DwmSetIconicLivePreviewBitmap(IntPtr hwnd, IntPtr hbmp, RefPOINT pptClient, DWM_SIT dwSITFlags); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("shell32.dll", PreserveSig = false)] + public static extern void SHGetItemFromDataObject(IDataObject pdtobj, DOGIF dwFlags, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("shell32.dll", PreserveSig = false)] + public static extern HRESULT SHCreateItemFromParsingName([MarshalAs(UnmanagedType.LPWStr)] string pszPath, IBindCtx pbc, [In] ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("shell32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool Shell_NotifyIcon(NIM dwMessage, [In] NOTIFYICONDATA lpdata); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("shell32.dll", PreserveSig = false)] + public static extern void SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("shell32.dll")] + public static extern HRESULT GetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] out string AppID); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDEXECOPT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDEXECOPT.cs new file mode 100644 index 00000000..4cf3a93d --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDEXECOPT.cs @@ -0,0 +1,12 @@ +using System; + +namespace Standard +{ + internal enum OLECMDEXECOPT + { + DODEFAULT, + PROMPTUSER, + DONTPROMPTUSER, + SHOWHELP + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDF.cs new file mode 100644 index 00000000..ea50ced3 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDF.cs @@ -0,0 +1,14 @@ +using System; + +namespace Standard +{ + internal enum OLECMDF + { + SUPPORTED = 1, + ENABLED, + LATCHED = 4, + NINCHED = 8, + INVISIBLE = 16, + DEFHIDEONCTXTMENU = 32 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDID.cs b/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDID.cs new file mode 100644 index 00000000..e23edebb --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/OLECMDID.cs @@ -0,0 +1,65 @@ +using System; + +namespace Standard +{ + internal enum OLECMDID + { + OPEN = 1, + NEW, + SAVE, + SAVEAS, + SAVECOPYAS, + PRINT, + PRINTPREVIEW, + PAGESETUP, + SPELL, + PROPERTIES, + CUT, + COPY, + PASTE, + PASTESPECIAL, + UNDO, + REDO, + SELECTALL, + CLEARSELECTION, + ZOOM, + GETZOOMRANGE, + UPDATECOMMANDS, + REFRESH, + STOP, + HIDETOOLBARS, + SETPROGRESSMAX, + SETPROGRESSPOS, + SETPROGRESSTEXT, + SETTITLE, + SETDOWNLOADSTATE, + STOPDOWNLOAD, + ONTOOLBARACTIVATED, + FIND, + DELETE, + HTTPEQUIV, + HTTPEQUIV_DONE, + ENABLE_INTERACTION, + ONUNLOAD, + PROPERTYBAG2, + PREREFRESH, + SHOWSCRIPTERROR, + SHOWMESSAGE, + SHOWFIND, + SHOWPAGESETUP, + SHOWPRINT, + CLOSE, + ALLOWUILESSSAVEAS, + DONTDOWNLOADCSS, + UPDATEPAGESTATUS, + PRINT2, + PRINTPREVIEW2, + SETPRINTTEMPLATE, + GETPRINTTEMPLATE, + PAGEACTIONBLOCKED = 55, + PAGEACTIONUIQUERY, + FOCUSVIEWCONTROLS, + FOCUSVIEWCONTROLSQUERY, + SHOWPAGEACTIONMENU + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/PKEY.cs b/src/Shared/Microsoft.Windows.Shell/Standard/PKEY.cs new file mode 100644 index 00000000..1c208591 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/PKEY.cs @@ -0,0 +1,31 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential, Pack = 4)] + internal struct PKEY + { + public PKEY(Guid fmtid, uint pid) + { + this._fmtid = fmtid; + this._pid = pid; + } + + private readonly Guid _fmtid; + + private readonly uint _pid; + + public static readonly PKEY Title = new PKEY(new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"), 2u); + + public static readonly PKEY AppUserModel_ID = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 5u); + + public static readonly PKEY AppUserModel_IsDestListSeparator = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 6u); + + public static readonly PKEY AppUserModel_RelaunchCommand = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 2u); + + public static readonly PKEY AppUserModel_RelaunchDisplayNameResource = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 4u); + + public static readonly PKEY AppUserModel_RelaunchIconResource = new PKEY(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 3u); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/POINT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/POINT.cs new file mode 100644 index 00000000..84f2b439 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/POINT.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal struct POINT + { + public int x; + + public int y; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/PROPVARIANT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/PROPVARIANT.cs new file mode 100644 index 00000000..03e3a463 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/PROPVARIANT.cs @@ -0,0 +1,94 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")] + [StructLayout(LayoutKind.Explicit)] + internal class PROPVARIANT : IDisposable + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public VarEnum VarType + { + get + { + return (VarEnum)this.vt; + } + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public string GetValue() + { + if (this.vt == 31) + { + return Marshal.PtrToStringUni(this.pointerVal); + } + return null; + } + + public void SetValue(bool f) + { + this.Clear(); + this.vt = 11; + this.boolVal = (short)(f ? -1 : 0); + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public void SetValue(string val) + { + this.Clear(); + this.vt = 31; + this.pointerVal = Marshal.StringToCoTaskMemUni(val); + } + + public void Clear() + { + PROPVARIANT.NativeMethods.PropVariantClear(this); + } + + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + ~PROPVARIANT() + { + this.Dispose(false); + } + + [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "disposing")] + private void Dispose(bool disposing) + { + this.Clear(); + } + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + [FieldOffset(0)] + private ushort vt; + + [SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + [FieldOffset(8)] + private IntPtr pointerVal; + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + [FieldOffset(8)] + private byte byteVal; + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + [FieldOffset(8)] + private long longVal; + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + [FieldOffset(8)] + private short boolVal; + + private static class NativeMethods + { + [DllImport("ole32.dll")] + internal static extern HRESULT PropVariantClear(PROPVARIANT pvar); + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/READYSTATE.cs b/src/Shared/Microsoft.Windows.Shell/Standard/READYSTATE.cs new file mode 100644 index 00000000..e565a879 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/READYSTATE.cs @@ -0,0 +1,13 @@ +using System; + +namespace Standard +{ + internal enum READYSTATE + { + UNINITIALIZED, + LOADING, + LOADED, + INTERACTIVE, + COMPLETE + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/RECT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/RECT.cs new file mode 100644 index 00000000..4057f3bc --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/RECT.cs @@ -0,0 +1,152 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Standard +{ + internal struct RECT + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public void Offset(int dx, int dy) + { + this._left += dx; + this._top += dy; + this._right += dx; + this._bottom += dy; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Left + { + get + { + return this._left; + } + set + { + this._left = value; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Right + { + get + { + return this._right; + } + set + { + this._right = value; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Top + { + get + { + return this._top; + } + set + { + this._top = value; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Bottom + { + get + { + return this._bottom; + } + set + { + this._bottom = value; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Width + { + get + { + return this._right - this._left; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Height + { + get + { + return this._bottom - this._top; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public POINT Position + { + get + { + return new POINT + { + x = this._left, + y = this._top + }; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public SIZE Size + { + get + { + return new SIZE + { + cx = this.Width, + cy = this.Height + }; + } + } + + public static RECT Union(RECT rect1, RECT rect2) + { + return new RECT + { + Left = Math.Min(rect1.Left, rect2.Left), + Top = Math.Min(rect1.Top, rect2.Top), + Right = Math.Max(rect1.Right, rect2.Right), + Bottom = Math.Max(rect1.Bottom, rect2.Bottom) + }; + } + + public override bool Equals(object obj) + { + bool result; + try + { + RECT rect = (RECT)obj; + result = (rect._bottom == this._bottom && rect._left == this._left && rect._right == this._right && rect._top == this._top); + } + catch (InvalidCastException) + { + result = false; + } + return result; + } + + public override int GetHashCode() + { + return (this._left << 16 | Utility.LOWORD(this._right)) ^ (this._top << 16 | Utility.LOWORD(this._bottom)); + } + + private int _left; + + private int _top; + + private int _right; + + private int _bottom; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/RGBQUAD.cs b/src/Shared/Microsoft.Windows.Shell/Standard/RGBQUAD.cs new file mode 100644 index 00000000..083300ef --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/RGBQUAD.cs @@ -0,0 +1,15 @@ +using System; + +namespace Standard +{ + internal struct RGBQUAD + { + public byte rgbBlue; + + public byte rgbGreen; + + public byte rgbRed; + + public byte rgbReserved; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/RGN.cs b/src/Shared/Microsoft.Windows.Shell/Standard/RGN.cs new file mode 100644 index 00000000..fc89b41d --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/RGN.cs @@ -0,0 +1,13 @@ +using System; + +namespace Standard +{ + internal enum RGN + { + AND = 1, + OR, + XOR, + DIFF, + COPY + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/RefPOINT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/RefPOINT.cs new file mode 100644 index 00000000..fe9182ff --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/RefPOINT.cs @@ -0,0 +1,15 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")] + [StructLayout(LayoutKind.Sequential)] + internal class RefPOINT + { + public int x; + + public int y; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/RefRECT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/RefRECT.cs new file mode 100644 index 00000000..e4dc2530 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/RefRECT.cs @@ -0,0 +1,107 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")] + [StructLayout(LayoutKind.Sequential)] + internal class RefRECT + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public RefRECT(int left, int top, int right, int bottom) + { + this._left = left; + this._top = top; + this._right = right; + this._bottom = bottom; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Width + { + get + { + return this._right - this._left; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Height + { + get + { + return this._bottom - this._top; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Left + { + get + { + return this._left; + } + set + { + this._left = value; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Right + { + get + { + return this._right; + } + set + { + this._right = value; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Top + { + get + { + return this._top; + } + set + { + this._top = value; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public int Bottom + { + get + { + return this._bottom; + } + set + { + this._bottom = value; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public void Offset(int dx, int dy) + { + this._left += dx; + this._top += dy; + this._right += dx; + this._bottom += dy; + } + + private int _left; + + private int _top; + + private int _right; + + private int _bottom; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SC.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SC.cs new file mode 100644 index 00000000..f3d3e92e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SC.cs @@ -0,0 +1,31 @@ +using System; + +namespace Standard +{ + internal enum SC + { + SIZE = 61440, + MOVE = 61456, + MINIMIZE = 61472, + MAXIMIZE = 61488, + NEXTWINDOW = 61504, + PREVWINDOW = 61520, + CLOSE = 61536, + VSCROLL = 61552, + HSCROLL = 61568, + MOUSEMENU = 61584, + KEYMENU = 61696, + ARRANGE = 61712, + RESTORE = 61728, + TASKLIST = 61744, + SCREENSAVE = 61760, + HOTKEY = 61776, + DEFAULT = 61792, + MONITORPOWER = 61808, + CONTEXTHELP = 61824, + SEPARATOR = 61455, + F_ISSECURE = 1, + ICON = 61472, + ZOOM = 61488 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SFGAO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SFGAO.cs new file mode 100644 index 00000000..62b64c48 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SFGAO.cs @@ -0,0 +1,43 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum SFGAO : uint + { + CANCOPY = 1u, + CANMOVE = 2u, + CANLINK = 4u, + STORAGE = 8u, + CANRENAME = 16u, + CANDELETE = 32u, + HASPROPSHEET = 64u, + DROPTARGET = 256u, + CAPABILITYMASK = 375u, + ENCRYPTED = 8192u, + ISSLOW = 16384u, + GHOSTED = 32768u, + LINK = 65536u, + SHARE = 131072u, + READONLY = 262144u, + HIDDEN = 524288u, + DISPLAYATTRMASK = 1032192u, + FILESYSANCESTOR = 268435456u, + FOLDER = 536870912u, + FILESYSTEM = 1073741824u, + HASSUBFOLDER = 2147483648u, + CONTENTSMASK = 2147483648u, + VALIDATE = 16777216u, + REMOVABLE = 33554432u, + COMPRESSED = 67108864u, + BROWSABLE = 134217728u, + NONENUMERATED = 1048576u, + NEWCONTENT = 2097152u, + CANMONIKER = 4194304u, + HASSTORAGE = 4194304u, + STREAM = 4194304u, + STORAGEANCESTOR = 8388608u, + STORAGECAPMASK = 1891958792u, + PKEYSFGAOMASK = 2164539392u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SHARD.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SHARD.cs new file mode 100644 index 00000000..9b4d33b3 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SHARD.cs @@ -0,0 +1,15 @@ +using System; + +namespace Standard +{ + internal enum SHARD + { + PIDL = 1, + PATHA, + PATHW, + APPIDINFO, + APPIDINFOIDLIST, + LINK, + APPIDINFOLINK + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFO.cs new file mode 100644 index 00000000..559499b1 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFO.cs @@ -0,0 +1,17 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + internal class SHARDAPPIDINFO + { + [MarshalAs(UnmanagedType.Interface)] + private object psi; + + [MarshalAs(UnmanagedType.LPWStr)] + private string pszAppID; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFOIDLIST.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFOIDLIST.cs new file mode 100644 index 00000000..014b4ae2 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFOIDLIST.cs @@ -0,0 +1,16 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + internal class SHARDAPPIDINFOIDLIST + { + private IntPtr pidl; + + [MarshalAs(UnmanagedType.LPWStr)] + private string pszAppID; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFOLINK.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFOLINK.cs new file mode 100644 index 00000000..0ec2386a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SHARDAPPIDINFOLINK.cs @@ -0,0 +1,16 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")] + [StructLayout(LayoutKind.Sequential, Pack = 4)] + internal class SHARDAPPIDINFOLINK + { + private IntPtr psl; + + [MarshalAs(UnmanagedType.LPWStr)] + private string pszAppID; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SHCONTF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SHCONTF.cs new file mode 100644 index 00000000..73de0c95 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SHCONTF.cs @@ -0,0 +1,20 @@ +using System; + +namespace Standard +{ + internal enum SHCONTF + { + CHECKING_FOR_CHILDREN = 16, + FOLDERS = 32, + NONFOLDERS = 64, + INCLUDEHIDDEN = 128, + INIT_ON_FIRST_NEXT = 256, + NETPRINTERSRCH = 512, + SHAREABLE = 1024, + STORAGE = 2048, + NAVIGATION_ENUM = 4096, + FASTITEMS = 8192, + FLATLIST = 16384, + ENABLE_ASYNC = 32768 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SHFILEOPSTRUCT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SHFILEOPSTRUCT.cs new file mode 100644 index 00000000..019f9166 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SHFILEOPSTRUCT.cs @@ -0,0 +1,28 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)] + internal struct SHFILEOPSTRUCT + { + public IntPtr hwnd; + + [MarshalAs(UnmanagedType.U4)] + public FO wFunc; + + public string pFrom; + + public string pTo; + + [MarshalAs(UnmanagedType.U2)] + public FOF fFlags; + + [MarshalAs(UnmanagedType.Bool)] + public int fAnyOperationsAborted; + + public IntPtr hNameMappings; + + public string lpszProgressTitle; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SHGDN.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SHGDN.cs new file mode 100644 index 00000000..54cce536 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SHGDN.cs @@ -0,0 +1,14 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum SHGDN + { + SHGDN_NORMAL = 0, + SHGDN_INFOLDER = 1, + SHGDN_FOREDITING = 4096, + SHGDN_FORADDRESSBAR = 16384, + SHGDN_FORPARSING = 32768 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SIATTRIBFLAGS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SIATTRIBFLAGS.cs new file mode 100644 index 00000000..822220b0 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SIATTRIBFLAGS.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal enum SIATTRIBFLAGS + { + AND = 1, + OR, + APPCOMPAT + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SICHINT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SICHINT.cs new file mode 100644 index 00000000..9d878b95 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SICHINT.cs @@ -0,0 +1,12 @@ +using System; + +namespace Standard +{ + internal enum SICHINT : uint + { + DISPLAY, + ALLFIELDS = 2147483648u, + CANONICAL = 268435456u, + TEST_FILESYSPATH_IF_NOT_EQUAL = 536870912u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SIGDN.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SIGDN.cs new file mode 100644 index 00000000..076b8517 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SIGDN.cs @@ -0,0 +1,17 @@ +using System; + +namespace Standard +{ + internal enum SIGDN : uint + { + NORMALDISPLAY, + PARENTRELATIVEPARSING = 2147581953u, + DESKTOPABSOLUTEPARSING = 2147647488u, + PARENTRELATIVEEDITING = 2147684353u, + DESKTOPABSOLUTEEDITING = 2147794944u, + FILESYSPATH = 2147844096u, + URL = 2147909632u, + PARENTRELATIVEFORADDRESSBAR = 2147991553u, + PARENTRELATIVE = 2148007937u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SIZE.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SIZE.cs new file mode 100644 index 00000000..9ba7cbda --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SIZE.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal struct SIZE + { + public int cx; + + public int cy; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SLGP.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SLGP.cs new file mode 100644 index 00000000..59b24c3b --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SLGP.cs @@ -0,0 +1,12 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum SLGP + { + SHORTPATH = 1, + UNCPRIORITY = 2, + RAWPATH = 4 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SM.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SM.cs new file mode 100644 index 00000000..50612bc8 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SM.cs @@ -0,0 +1,92 @@ +using System; + +namespace Standard +{ + internal enum SM + { + CXSCREEN, + CYSCREEN, + CXVSCROLL, + CYHSCROLL, + CYCAPTION, + CXBORDER, + CYBORDER, + CXFIXEDFRAME, + CYFIXEDFRAME, + CYVTHUMB, + CXHTHUMB, + CXICON, + CYICON, + CXCURSOR, + CYCURSOR, + CYMENU, + CXFULLSCREEN, + CYFULLSCREEN, + CYKANJIWINDOW, + MOUSEPRESENT, + CYVSCROLL, + CXHSCROLL, + DEBUG, + SWAPBUTTON, + CXMIN = 28, + CYMIN, + CXSIZE, + CYSIZE, + CXFRAME, + CXSIZEFRAME = 32, + CYFRAME, + CYSIZEFRAME = 33, + CXMINTRACK, + CYMINTRACK, + CXDOUBLECLK, + CYDOUBLECLK, + CXICONSPACING, + CYICONSPACING, + MENUDROPALIGNMENT, + PENWINDOWS, + DBCSENABLED, + CMOUSEBUTTONS, + SECURE, + CXEDGE, + CYEDGE, + CXMINSPACING, + CYMINSPACING, + CXSMICON, + CYSMICON, + CYSMCAPTION, + CXSMSIZE, + CYSMSIZE, + CXMENUSIZE, + CYMENUSIZE, + ARRANGE, + CXMINIMIZED, + CYMINIMIZED, + CXMAXTRACK, + CYMAXTRACK, + CXMAXIMIZED, + CYMAXIMIZED, + NETWORK, + CLEANBOOT = 67, + CXDRAG, + CYDRAG, + SHOWSOUNDS, + CXMENUCHECK, + CYMENUCHECK, + SLOWMACHINE, + MIDEASTENABLED, + MOUSEWHEELPRESENT, + XVIRTUALSCREEN, + YVIRTUALSCREEN, + CXVIRTUALSCREEN, + CYVIRTUALSCREEN, + CMONITORS, + SAMEDISPLAYFORMAT, + IMMENABLED, + CXFOCUSBORDER, + CYFOCUSBORDER, + TABLETPC = 86, + MEDIACENTER, + REMOTESESSION = 4096, + REMOTECONTROL = 8193 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SPI.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SPI.cs new file mode 100644 index 00000000..e500d147 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SPI.cs @@ -0,0 +1,223 @@ +using System; + +namespace Standard +{ + internal enum SPI + { + GETBEEP = 1, + SETBEEP, + GETMOUSE, + SETMOUSE, + GETBORDER, + SETBORDER, + GETKEYBOARDSPEED = 10, + SETKEYBOARDSPEED, + LANGDRIVER, + ICONHORIZONTALSPACING, + GETSCREENSAVETIMEOUT, + SETSCREENSAVETIMEOUT, + GETSCREENSAVEACTIVE, + SETSCREENSAVEACTIVE, + GETGRIDGRANULARITY, + SETGRIDGRANULARITY, + SETDESKWALLPAPER, + SETDESKPATTERN, + GETKEYBOARDDELAY, + SETKEYBOARDDELAY, + ICONVERTICALSPACING, + GETICONTITLEWRAP, + SETICONTITLEWRAP, + GETMENUDROPALIGNMENT, + SETMENUDROPALIGNMENT, + SETDOUBLECLKWIDTH, + SETDOUBLECLKHEIGHT, + GETICONTITLELOGFONT, + SETDOUBLECLICKTIME, + SETMOUSEBUTTONSWAP, + SETICONTITLELOGFONT, + GETFASTTASKSWITCH, + SETFASTTASKSWITCH, + SETDRAGFULLWINDOWS, + GETDRAGFULLWINDOWS, + GETNONCLIENTMETRICS = 41, + SETNONCLIENTMETRICS, + GETMINIMIZEDMETRICS, + SETMINIMIZEDMETRICS, + GETICONMETRICS, + SETICONMETRICS, + SETWORKAREA, + GETWORKAREA, + SETPENWINDOWS, + GETHIGHCONTRAST = 66, + SETHIGHCONTRAST, + GETKEYBOARDPREF, + SETKEYBOARDPREF, + GETSCREENREADER, + SETSCREENREADER, + GETANIMATION, + SETANIMATION, + GETFONTSMOOTHING, + SETFONTSMOOTHING, + SETDRAGWIDTH, + SETDRAGHEIGHT, + SETHANDHELD, + GETLOWPOWERTIMEOUT, + GETPOWEROFFTIMEOUT, + SETLOWPOWERTIMEOUT, + SETPOWEROFFTIMEOUT, + GETLOWPOWERACTIVE, + GETPOWEROFFACTIVE, + SETLOWPOWERACTIVE, + SETPOWEROFFACTIVE, + SETCURSORS, + SETICONS, + GETDEFAULTINPUTLANG, + SETDEFAULTINPUTLANG, + SETLANGTOGGLE, + GETWINDOWSEXTENSION, + SETMOUSETRAILS, + GETMOUSETRAILS, + SETSCREENSAVERRUNNING = 97, + SCREENSAVERRUNNING = 97, + GETFILTERKEYS = 50, + SETFILTERKEYS, + GETTOGGLEKEYS, + SETTOGGLEKEYS, + GETMOUSEKEYS, + SETMOUSEKEYS, + GETSHOWSOUNDS, + SETSHOWSOUNDS, + GETSTICKYKEYS, + SETSTICKYKEYS, + GETACCESSTIMEOUT, + SETACCESSTIMEOUT, + GETSERIALKEYS, + SETSERIALKEYS, + GETSOUNDSENTRY, + SETSOUNDSENTRY, + GETSNAPTODEFBUTTON = 95, + SETSNAPTODEFBUTTON, + GETMOUSEHOVERWIDTH = 98, + SETMOUSEHOVERWIDTH, + GETMOUSEHOVERHEIGHT, + SETMOUSEHOVERHEIGHT, + GETMOUSEHOVERTIME, + SETMOUSEHOVERTIME, + GETWHEELSCROLLLINES, + SETWHEELSCROLLLINES, + GETMENUSHOWDELAY, + SETMENUSHOWDELAY, + GETWHEELSCROLLCHARS, + SETWHEELSCROLLCHARS, + GETSHOWIMEUI, + SETSHOWIMEUI, + GETMOUSESPEED, + SETMOUSESPEED, + GETSCREENSAVERRUNNING, + GETDESKWALLPAPER, + GETAUDIODESCRIPTION, + SETAUDIODESCRIPTION, + GETSCREENSAVESECURE, + SETSCREENSAVESECURE, + GETHUNGAPPTIMEOUT, + SETHUNGAPPTIMEOUT, + GETWAITTOKILLTIMEOUT, + SETWAITTOKILLTIMEOUT, + GETWAITTOKILLSERVICETIMEOUT, + SETWAITTOKILLSERVICETIMEOUT, + GETMOUSEDOCKTHRESHOLD, + SETMOUSEDOCKTHRESHOLD, + GETPENDOCKTHRESHOLD, + SETPENDOCKTHRESHOLD, + GETWINARRANGING, + SETWINARRANGING, + GETMOUSEDRAGOUTTHRESHOLD, + SETMOUSEDRAGOUTTHRESHOLD, + GETPENDRAGOUTTHRESHOLD, + SETPENDRAGOUTTHRESHOLD, + GETMOUSESIDEMOVETHRESHOLD, + SETMOUSESIDEMOVETHRESHOLD, + GETPENSIDEMOVETHRESHOLD, + SETPENSIDEMOVETHRESHOLD, + GETDRAGFROMMAXIMIZE, + SETDRAGFROMMAXIMIZE, + GETSNAPSIZING, + SETSNAPSIZING, + GETDOCKMOVING, + SETDOCKMOVING, + GETACTIVEWINDOWTRACKING = 4096, + SETACTIVEWINDOWTRACKING, + GETMENUANIMATION, + SETMENUANIMATION, + GETCOMBOBOXANIMATION, + SETCOMBOBOXANIMATION, + GETLISTBOXSMOOTHSCROLLING, + SETLISTBOXSMOOTHSCROLLING, + GETGRADIENTCAPTIONS, + SETGRADIENTCAPTIONS, + GETKEYBOARDCUES, + SETKEYBOARDCUES, + GETMENUUNDERLINES = 4106, + SETMENUUNDERLINES, + GETACTIVEWNDTRKZORDER, + SETACTIVEWNDTRKZORDER, + GETHOTTRACKING, + SETHOTTRACKING, + GETMENUFADE = 4114, + SETMENUFADE, + GETSELECTIONFADE, + SETSELECTIONFADE, + GETTOOLTIPANIMATION, + SETTOOLTIPANIMATION, + GETTOOLTIPFADE, + SETTOOLTIPFADE, + GETCURSORSHADOW, + SETCURSORSHADOW, + GETMOUSESONAR, + SETMOUSESONAR, + GETMOUSECLICKLOCK, + SETMOUSECLICKLOCK, + GETMOUSEVANISH, + SETMOUSEVANISH, + GETFLATMENU, + SETFLATMENU, + GETDROPSHADOW, + SETDROPSHADOW, + GETBLOCKSENDINPUTRESETS, + SETBLOCKSENDINPUTRESETS, + GETUIEFFECTS = 4158, + SETUIEFFECTS, + GETDISABLEOVERLAPPEDCONTENT, + SETDISABLEOVERLAPPEDCONTENT, + GETCLIENTAREAANIMATION, + SETCLIENTAREAANIMATION, + GETCLEARTYPE = 4168, + SETCLEARTYPE, + GETSPEECHRECOGNITION, + SETSPEECHRECOGNITION, + GETFOREGROUNDLOCKTIMEOUT = 8192, + SETFOREGROUNDLOCKTIMEOUT, + GETACTIVEWNDTRKTIMEOUT, + SETACTIVEWNDTRKTIMEOUT, + GETFOREGROUNDFLASHCOUNT, + SETFOREGROUNDFLASHCOUNT, + GETCARETWIDTH, + SETCARETWIDTH, + GETMOUSECLICKLOCKTIME, + SETMOUSECLICKLOCKTIME, + GETFONTSMOOTHINGTYPE, + SETFONTSMOOTHINGTYPE, + GETFONTSMOOTHINGCONTRAST, + SETFONTSMOOTHINGCONTRAST, + GETFOCUSBORDERWIDTH, + SETFOCUSBORDERWIDTH, + GETFOCUSBORDERHEIGHT, + SETFOCUSBORDERHEIGHT, + GETFONTSMOOTHINGORIENTATION, + SETFONTSMOOTHINGORIENTATION, + GETMINIMUMHITRADIUS, + SETMINIMUMHITRADIUS, + GETMESSAGEDURATION, + SETMESSAGEDURATION + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SPIF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SPIF.cs new file mode 100644 index 00000000..72a28d09 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SPIF.cs @@ -0,0 +1,13 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum SPIF + { + None = 0, + UPDATEINIFILE = 1, + SENDCHANGE = 2, + SENDWININICHANGE = 2 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/STATE_SYSTEM.cs b/src/Shared/Microsoft.Windows.Shell/Standard/STATE_SYSTEM.cs new file mode 100644 index 00000000..4b725df9 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/STATE_SYSTEM.cs @@ -0,0 +1,41 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum STATE_SYSTEM + { + UNAVAILABLE = 1, + SELECTED = 2, + FOCUSED = 4, + PRESSED = 8, + CHECKED = 16, + MIXED = 32, + INDETERMINATE = 32, + READONLY = 64, + HOTTRACKED = 128, + DEFAULT = 256, + EXPANDED = 512, + COLLAPSED = 1024, + BUSY = 2048, + FLOATING = 4096, + MARQUEED = 8192, + ANIMATED = 16384, + INVISIBLE = 32768, + OFFSCREEN = 65536, + SIZEABLE = 131072, + MOVEABLE = 262144, + SELFVOICING = 524288, + FOCUSABLE = 1048576, + SELECTABLE = 2097152, + LINKED = 4194304, + TRAVERSED = 8388608, + MULTISELECTABLE = 16777216, + EXTSELECTABLE = 33554432, + ALERT_LOW = 67108864, + ALERT_MEDIUM = 134217728, + ALERT_HIGH = 268435456, + PROTECTED = 536870912, + VALID = 1073741823 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/STPF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/STPF.cs new file mode 100644 index 00000000..2e6b438d --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/STPF.cs @@ -0,0 +1,14 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum STPF + { + NONE = 0, + USEAPPTHUMBNAILALWAYS = 1, + USEAPPTHUMBNAILWHENACTIVE = 2, + USEAPPPEEKALWAYS = 4, + USEAPPPEEKWHENACTIVE = 8 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/STR_GPS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/STR_GPS.cs new file mode 100644 index 00000000..865ba4f2 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/STR_GPS.cs @@ -0,0 +1,19 @@ +using System; + +namespace Standard +{ + internal static class STR_GPS + { + public const string HANDLERPROPERTIESONLY = "GPS_HANDLERPROPERTIESONLY"; + + public const string FASTPROPERTIESONLY = "GPS_FASTPROPERTIESONLY"; + + public const string OPENSLOWITEM = "GPS_OPENSLOWITEM"; + + public const string DELAYCREATION = "GPS_DELAYCREATION"; + + public const string BESTEFFORT = "GPS_BESTEFFORT"; + + public const string NO_OPLOCK = "GPS_NO_OPLOCK"; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SW.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SW.cs new file mode 100644 index 00000000..96a6662e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SW.cs @@ -0,0 +1,22 @@ +using System; + +namespace Standard +{ + internal enum SW + { + HIDE, + SHOWNORMAL, + NORMAL = 1, + SHOWMINIMIZED, + SHOWMAXIMIZED, + MAXIMIZE = 3, + SHOWNOACTIVATE, + SHOW, + MINIMIZE, + SHOWMINNOACTIVE, + SHOWNA, + RESTORE, + SHOWDEFAULT, + FORCEMINIMIZE + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SWP.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SWP.cs new file mode 100644 index 00000000..02079a58 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SWP.cs @@ -0,0 +1,24 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum SWP + { + ASYNCWINDOWPOS = 16384, + DEFERERASE = 8192, + DRAWFRAME = 32, + FRAMECHANGED = 32, + HIDEWINDOW = 128, + NOACTIVATE = 16, + NOCOPYBITS = 256, + NOMOVE = 2, + NOOWNERZORDER = 512, + NOREDRAW = 8, + NOREPOSITION = 512, + NOSENDCHANGING = 1024, + NOSIZE = 1, + NOZORDER = 4, + SHOWWINDOW = 64 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SafeConnectionPointCookie.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SafeConnectionPointCookie.cs new file mode 100644 index 00000000..d8c94527 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SafeConnectionPointCookie.cs @@ -0,0 +1,76 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.ConstrainedExecution; +using System.Runtime.InteropServices.ComTypes; +using Microsoft.Win32.SafeHandles; + +namespace Standard +{ + internal sealed class SafeConnectionPointCookie : SafeHandleZeroOrMinusOneIsInvalid + { + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "IConnectionPoint")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public SafeConnectionPointCookie(IConnectionPointContainer target, object sink, Guid eventId) : base(true) + { + Verify.IsNotNull(target, "target"); + Verify.IsNotNull(sink, "sink"); + Verify.IsNotDefault(eventId, "eventId"); + this.handle = IntPtr.Zero; + IConnectionPoint connectionPoint = null; + try + { + target.FindConnectionPoint(ref eventId, out connectionPoint); + int num; + connectionPoint.Advise(sink, out num); + if (num == 0) + { + throw new InvalidOperationException("IConnectionPoint::Advise returned an invalid cookie."); + } + this.handle = new IntPtr(num); + this._cp = connectionPoint; + connectionPoint = null; + } + finally + { + Utility.SafeRelease(ref connectionPoint); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public void Disconnect() + { + this.ReleaseHandle(); + } + + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] + protected override bool ReleaseHandle() + { + bool result; + try + { + if (!this.IsInvalid) + { + int dwCookie = this.handle.ToInt32(); + this.handle = IntPtr.Zero; + try + { + this._cp.Unadvise(dwCookie); + } + finally + { + Utility.SafeRelease(ref this._cp); + } + } + result = true; + } + catch + { + result = false; + } + return result; + } + + private IConnectionPoint _cp; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SafeDC.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SafeDC.cs new file mode 100644 index 00000000..a015802b --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SafeDC.cs @@ -0,0 +1,156 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.ConstrainedExecution; +using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; + +namespace Standard +{ + internal sealed class SafeDC : SafeHandleZeroOrMinusOneIsInvalid + { + public IntPtr Hwnd + { + set + { + this._hwnd = new IntPtr?(value); + } + } + + private SafeDC() : base(true) + { + } + + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] + protected override bool ReleaseHandle() + { + if (this._created) + { + return SafeDC.NativeMethods.DeleteDC(this.handle); + } + return this._hwnd == null || this._hwnd.Value == IntPtr.Zero || SafeDC.NativeMethods.ReleaseDC(this._hwnd.Value, this.handle) == 1; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes")] + public static SafeDC CreateDC(string deviceName) + { + SafeDC safeDC = null; + try + { + safeDC = SafeDC.NativeMethods.CreateDC(deviceName, null, IntPtr.Zero, IntPtr.Zero); + } + finally + { + if (safeDC != null) + { + safeDC._created = true; + } + } + if (safeDC.IsInvalid) + { + safeDC.Dispose(); + throw new SystemException("Unable to create a device context from the specified device information."); + } + return safeDC; + } + + [SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static SafeDC CreateCompatibleDC(SafeDC hdc) + { + SafeDC safeDC = null; + try + { + IntPtr hdc2 = IntPtr.Zero; + if (hdc != null) + { + hdc2 = hdc.handle; + } + safeDC = SafeDC.NativeMethods.CreateCompatibleDC(hdc2); + if (safeDC == null) + { + HRESULT.ThrowLastError(); + } + } + finally + { + if (safeDC != null) + { + safeDC._created = true; + } + } + if (safeDC.IsInvalid) + { + safeDC.Dispose(); + throw new SystemException("Unable to create a device context from the specified device information."); + } + return safeDC; + } + + public static SafeDC GetDC(IntPtr hwnd) + { + SafeDC safeDC = null; + try + { + safeDC = SafeDC.NativeMethods.GetDC(hwnd); + } + finally + { + if (safeDC != null) + { + safeDC.Hwnd = hwnd; + } + } + if (safeDC.IsInvalid) + { + HRESULT.E_FAIL.ThrowIfFailed(); + } + return safeDC; + } + + public static SafeDC GetDesktop() + { + return SafeDC.GetDC(IntPtr.Zero); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] + public static SafeDC WrapDC(IntPtr hdc) + { + return new SafeDC + { + handle = hdc, + _created = false, + _hwnd = new IntPtr?(IntPtr.Zero) + }; + } + + private IntPtr? _hwnd; + + private bool _created; + + private static class NativeMethods + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll")] + public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("user32.dll")] + public static extern SafeDC GetDC(IntPtr hwnd); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", CharSet = CharSet.Unicode)] + public static extern SafeDC CreateDC([MarshalAs(UnmanagedType.LPWStr)] string lpszDriver, [MarshalAs(UnmanagedType.LPWStr)] string lpszDevice, IntPtr lpszOutput, IntPtr lpInitData); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + public static extern SafeDC CreateCompatibleDC(IntPtr hdc); + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DllImport("gdi32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool DeleteDC(IntPtr hdc); + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SafeFindHandle.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SafeFindHandle.cs new file mode 100644 index 00000000..f7cf61bc --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SafeFindHandle.cs @@ -0,0 +1,19 @@ +using System; +using System.Security.Permissions; +using Microsoft.Win32.SafeHandles; + +namespace Standard +{ + internal sealed class SafeFindHandle : SafeHandleZeroOrMinusOneIsInvalid + { + [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] + private SafeFindHandle() : base(true) + { + } + + protected override bool ReleaseHandle() + { + return NativeMethods.FindClose(this.handle); + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SafeGdiplusStartupToken.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SafeGdiplusStartupToken.cs new file mode 100644 index 00000000..915025ba --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SafeGdiplusStartupToken.cs @@ -0,0 +1,38 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.ConstrainedExecution; +using Microsoft.Win32.SafeHandles; + +namespace Standard +{ + internal sealed class SafeGdiplusStartupToken : SafeHandleZeroOrMinusOneIsInvalid + { + private SafeGdiplusStartupToken() : base(true) + { + } + + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] + protected override bool ReleaseHandle() + { + Status status = NativeMethods.GdiplusShutdown(this.handle); + return status == Status.Ok; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] + [SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes")] + public static SafeGdiplusStartupToken Startup() + { + SafeGdiplusStartupToken safeGdiplusStartupToken = new SafeGdiplusStartupToken(); + IntPtr handle; + StartupOutput startupOutput; + if (NativeMethods.GdiplusStartup(out handle, new StartupInput(), out startupOutput) == Status.Ok) + { + safeGdiplusStartupToken.handle = handle; + return safeGdiplusStartupToken; + } + safeGdiplusStartupToken.Dispose(); + throw new Exception("Unable to initialize GDI+"); + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/SafeHBITMAP.cs b/src/Shared/Microsoft.Windows.Shell/Standard/SafeHBITMAP.cs new file mode 100644 index 00000000..508af7aa --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/SafeHBITMAP.cs @@ -0,0 +1,19 @@ +using System; +using System.Runtime.ConstrainedExecution; +using Microsoft.Win32.SafeHandles; + +namespace Standard +{ + internal sealed class SafeHBITMAP : SafeHandleZeroOrMinusOneIsInvalid + { + private SafeHBITMAP() : base(true) + { + } + + [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] + protected override bool ReleaseHandle() + { + return NativeMethods.DeleteObject(this.handle); + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/StartupInput.cs b/src/Shared/Microsoft.Windows.Shell/Standard/StartupInput.cs new file mode 100644 index 00000000..1bfe859d --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/StartupInput.cs @@ -0,0 +1,17 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential)] + internal class StartupInput + { + public int GdiplusVersion = 1; + + public IntPtr DebugEventCallback; + + public bool SuppressBackgroundThread; + + public bool SuppressExternalCodecs; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/StartupOutput.cs b/src/Shared/Microsoft.Windows.Shell/Standard/StartupOutput.cs new file mode 100644 index 00000000..29c9243d --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/StartupOutput.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal struct StartupOutput + { + public IntPtr hook; + + public IntPtr unhook; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/Status.cs b/src/Shared/Microsoft.Windows.Shell/Standard/Status.cs new file mode 100644 index 00000000..c84e8ffe --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/Status.cs @@ -0,0 +1,30 @@ +using System; + +namespace Standard +{ + internal enum Status + { + Ok, + GenericError, + InvalidParameter, + OutOfMemory, + ObjectBusy, + InsufficientBuffer, + NotImplemented, + Win32Error, + WrongState, + Aborted, + FileNotFound, + ValueOverflow, + AccessDenied, + UnknownImageFormat, + FontFamilyNotFound, + FontStyleNotFound, + NotTrueTypeFont, + UnsupportedGdiplusVersion, + GdiplusNotInitialized, + PropertyNotFound, + PropertyNotSupported, + ProfileNotFound + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/StockObject.cs b/src/Shared/Microsoft.Windows.Shell/Standard/StockObject.cs new file mode 100644 index 00000000..09060902 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/StockObject.cs @@ -0,0 +1,20 @@ +using System; + +namespace Standard +{ + internal enum StockObject + { + WHITE_BRUSH, + LTGRAY_BRUSH, + GRAY_BRUSH, + DKGRAY_BRUSH, + BLACK_BRUSH, + NULL_BRUSH, + HOLLOW_BRUSH = 5, + WHITE_PEN, + BLACK_PEN, + NULL_PEN, + SYSTEM_FONT = 13, + DEFAULT_PALETTE = 15 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/TBPF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/TBPF.cs new file mode 100644 index 00000000..40e1c70c --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/TBPF.cs @@ -0,0 +1,13 @@ +using System; + +namespace Standard +{ + internal enum TBPF + { + NOPROGRESS, + INDETERMINATE, + NORMAL, + ERROR = 4, + PAUSED = 8 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/THB.cs b/src/Shared/Microsoft.Windows.Shell/Standard/THB.cs new file mode 100644 index 00000000..6d59bd3f --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/THB.cs @@ -0,0 +1,13 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum THB : uint + { + BITMAP = 1u, + ICON = 2u, + TOOLTIP = 4u, + FLAGS = 8u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/THBF.cs b/src/Shared/Microsoft.Windows.Shell/Standard/THBF.cs new file mode 100644 index 00000000..ac17b593 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/THBF.cs @@ -0,0 +1,15 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum THBF : uint + { + ENABLED = 0u, + DISABLED = 1u, + DISMISSONCLICK = 2u, + NOBACKGROUND = 4u, + HIDDEN = 8u, + NONINTERACTIVE = 16u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/THUMBBUTTON.cs b/src/Shared/Microsoft.Windows.Shell/Standard/THUMBBUTTON.cs new file mode 100644 index 00000000..a938d3fd --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/THUMBBUTTON.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 8)] + internal struct THUMBBUTTON + { + public const int THBN_CLICKED = 6144; + + public THB dwMask; + + public uint iId; + + public uint iBitmap; + + public IntPtr hIcon; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] + public string szTip; + + public THBF dwFlags; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/TITLEBARINFO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/TITLEBARINFO.cs new file mode 100644 index 00000000..da93a117 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/TITLEBARINFO.cs @@ -0,0 +1,23 @@ +using System; + +namespace Standard +{ + internal struct TITLEBARINFO + { + public int cbSize; + + public RECT rcTitleBar; + + public STATE_SYSTEM rgstate_TitleBar; + + public STATE_SYSTEM rgstate_Reserved; + + public STATE_SYSTEM rgstate_MinimizeButton; + + public STATE_SYSTEM rgstate_MaximizeButton; + + public STATE_SYSTEM rgstate_HelpButton; + + public STATE_SYSTEM rgstate_CloseButton; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/TITLEBARINFOEX.cs b/src/Shared/Microsoft.Windows.Shell/Standard/TITLEBARINFOEX.cs new file mode 100644 index 00000000..ea7b28db --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/TITLEBARINFOEX.cs @@ -0,0 +1,35 @@ +using System; + +namespace Standard +{ + internal struct TITLEBARINFOEX + { + public int cbSize; + + public RECT rcTitleBar; + + public STATE_SYSTEM rgstate_TitleBar; + + public STATE_SYSTEM rgstate_Reserved; + + public STATE_SYSTEM rgstate_MinimizeButton; + + public STATE_SYSTEM rgstate_MaximizeButton; + + public STATE_SYSTEM rgstate_HelpButton; + + public STATE_SYSTEM rgstate_CloseButton; + + public RECT rgrect_TitleBar; + + public RECT rgrect_Reserved; + + public RECT rgrect_MinimizeButton; + + public RECT rgrect_MaximizeButton; + + public RECT rgrect_HelpButton; + + public RECT rgrect_CloseButton; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/ULW.cs b/src/Shared/Microsoft.Windows.Shell/Standard/ULW.cs new file mode 100644 index 00000000..c69d1286 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/ULW.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal enum ULW + { + ALPHA = 2, + COLORKEY = 1, + OPAQUE = 4 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/UNSIGNED_RATIO.cs b/src/Shared/Microsoft.Windows.Shell/Standard/UNSIGNED_RATIO.cs new file mode 100644 index 00000000..98db9fd2 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/UNSIGNED_RATIO.cs @@ -0,0 +1,11 @@ +using System; + +namespace Standard +{ + internal struct UNSIGNED_RATIO + { + public uint uiNumerator; + + public uint uiDenominator; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/Utility.cs b/src/Shared/Microsoft.Windows.Shell/Standard/Utility.cs new file mode 100644 index 00000000..3e1a566c --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/Utility.cs @@ -0,0 +1,822 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Security.Cryptography; +using System.Text; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace Standard +{ + internal static class Utility + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + private static bool _MemCmp(IntPtr left, IntPtr right, long cb) + { + int num = 0; + while ((long)num < cb - 8L) + { + long num2 = Marshal.ReadInt64(left, num); + long num3 = Marshal.ReadInt64(right, num); + if (num2 != num3) + { + return false; + } + num += 8; + } + while ((long)num < cb) + { + byte b = Marshal.ReadByte(left, num); + byte b2 = Marshal.ReadByte(right, num); + if (b != b2) + { + return false; + } + num++; + } + return true; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static int RGB(Color c) + { + return (int)c.R | (int)c.G << 8 | (int)c.B << 16; + } + + public static Color ColorFromArgbDword(uint color) + { + return Color.FromArgb((byte)((color & 4278190080u) >> 24), (byte)((color & 16711680u) >> 16), (byte)((color & 65280u) >> 8), (byte)(color & 255u)); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static int GET_X_LPARAM(IntPtr lParam) + { + return Utility.LOWORD(lParam.ToInt32()); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static int GET_Y_LPARAM(IntPtr lParam) + { + return Utility.HIWORD(lParam.ToInt32()); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static int HIWORD(int i) + { + return (int)((short)(i >> 16)); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static int LOWORD(int i) + { + return (int)((short)(i & 65535)); + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool AreStreamsEqual(Stream left, Stream right) + { + if (left == null) + { + return right == null; + } + if (right == null) + { + return false; + } + if (!left.CanRead || !right.CanRead) + { + throw new NotSupportedException("The streams can't be read for comparison"); + } + if (left.Length != right.Length) + { + return false; + } + int num = (int)left.Length; + left.Position = 0L; + right.Position = 0L; + int i = 0; + int num2 = 0; + byte[] array = new byte[512]; + byte[] array2 = new byte[512]; + GCHandle gchandle = GCHandle.Alloc(array, GCHandleType.Pinned); + IntPtr left2 = gchandle.AddrOfPinnedObject(); + GCHandle gchandle2 = GCHandle.Alloc(array2, GCHandleType.Pinned); + IntPtr right2 = gchandle2.AddrOfPinnedObject(); + bool result; + try + { + while (i < num) + { + int num3 = left.Read(array, 0, array.Length); + int num4 = right.Read(array2, 0, array2.Length); + if (num3 != num4) + { + return false; + } + if (!Utility._MemCmp(left2, right2, (long)num3)) + { + return false; + } + i += num3; + num2 += num4; + } + result = true; + } + finally + { + gchandle.Free(); + gchandle2.Free(); + } + return result; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool GuidTryParse(string guidString, out Guid guid) + { + Verify.IsNeitherNullNorEmpty(guidString, "guidString"); + try + { + guid = new Guid(guidString); + return true; + } + catch (FormatException) + { + } + catch (OverflowException) + { + } + guid = default(Guid); + return false; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool IsFlagSet(int value, int mask) + { + return 0 != (value & mask); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool IsFlagSet(uint value, uint mask) + { + return 0u != (value & mask); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool IsFlagSet(long value, long mask) + { + return 0L != (value & mask); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool IsFlagSet(ulong value, ulong mask) + { + return 0UL != (value & mask); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool IsOSVistaOrNewer + { + get + { + return Utility._osVersion >= new Version(6, 0); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool IsOSWindows7OrNewer + { + get + { + return Utility._osVersion >= new Version(6, 1); + } + } + + public static bool IsPresentationFrameworkVersionLessThan4 + { + get + { + return Utility._presentationFrameworkVersion < new Version(4, 0); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")] + public static IntPtr GenerateHICON(ImageSource image, Size dimensions) + { + if (image == null) + { + return IntPtr.Zero; + } + BitmapFrame bitmapFrame = image as BitmapFrame; + if (bitmapFrame != null) + { + bitmapFrame = Utility.GetBestMatch(bitmapFrame.Decoder.Frames, (int)dimensions.Width, (int)dimensions.Height); + } + else + { + Rect rectangle = new Rect(0.0, 0.0, dimensions.Width, dimensions.Height); + double num = dimensions.Width / dimensions.Height; + double num2 = image.Width / image.Height; + if (image.Width <= dimensions.Width && image.Height <= dimensions.Height) + { + rectangle = new Rect((dimensions.Width - image.Width) / 2.0, (dimensions.Height - image.Height) / 2.0, image.Width, image.Height); + } + else if (num > num2) + { + double num3 = image.Width / image.Height * dimensions.Width; + rectangle = new Rect((dimensions.Width - num3) / 2.0, 0.0, num3, dimensions.Height); + } + else if (num < num2) + { + double num4 = image.Height / image.Width * dimensions.Height; + rectangle = new Rect(0.0, (dimensions.Height - num4) / 2.0, dimensions.Width, num4); + } + DrawingVisual drawingVisual = new DrawingVisual(); + DrawingContext drawingContext = drawingVisual.RenderOpen(); + drawingContext.DrawImage(image, rectangle); + drawingContext.Close(); + RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)dimensions.Width, (int)dimensions.Height, 96.0, 96.0, PixelFormats.Pbgra32); + renderTargetBitmap.Render(drawingVisual); + bitmapFrame = BitmapFrame.Create(renderTargetBitmap); + } + IntPtr result; + using (MemoryStream memoryStream = new MemoryStream()) + { + new PngBitmapEncoder + { + Frames = + { + bitmapFrame + } + }.Save(memoryStream); + using (ManagedIStream managedIStream = new ManagedIStream(memoryStream)) + { + IntPtr zero = IntPtr.Zero; + try + { + Status status = NativeMethods.GdipCreateBitmapFromStream(managedIStream, out zero); + if (status != Status.Ok) + { + result = IntPtr.Zero; + } + else + { + IntPtr intPtr; + status = NativeMethods.GdipCreateHICONFromBitmap(zero, out intPtr); + if (status != Status.Ok) + { + result = IntPtr.Zero; + } + else + { + result = intPtr; + } + } + } + finally + { + Utility.SafeDisposeImage(ref zero); + } + } + } + return result; + } + + public static BitmapFrame GetBestMatch(IList frames, int width, int height) + { + return Utility._GetBestMatch(frames, Utility._GetBitDepth(), width, height); + } + + private static int _MatchImage(BitmapFrame frame, int bitDepth, int width, int height, int bpp) + { + return 2 * Utility._WeightedAbs(bpp, bitDepth, false) + Utility._WeightedAbs(frame.PixelWidth, width, true) + Utility._WeightedAbs(frame.PixelHeight, height, true); + } + + private static int _WeightedAbs(int valueHave, int valueWant, bool fPunish) + { + int num = valueHave - valueWant; + if (num < 0) + { + num = (fPunish ? -2 : -1) * num; + } + return num; + } + + private static BitmapFrame _GetBestMatch(IList frames, int bitDepth, int width, int height) + { + int num = int.MaxValue; + int num2 = 0; + int index = 0; + bool flag = frames[0].Decoder is IconBitmapDecoder; + int num3 = 0; + while (num3 < frames.Count && num != 0) + { + int num4 = flag ? frames[num3].Thumbnail.Format.BitsPerPixel : frames[num3].Format.BitsPerPixel; + if (num4 == 0) + { + num4 = 8; + } + int num5 = Utility._MatchImage(frames[num3], bitDepth, width, height, num4); + if (num5 < num) + { + index = num3; + num2 = num4; + num = num5; + } + else if (num5 == num && num2 < num4) + { + index = num3; + num2 = num4; + } + num3++; + } + return frames[index]; + } + + private static int _GetBitDepth() + { + if (Utility.s_bitDepth == 0) + { + using (SafeDC desktop = SafeDC.GetDesktop()) + { + Utility.s_bitDepth = NativeMethods.GetDeviceCaps(desktop, DeviceCap.BITSPIXEL) * NativeMethods.GetDeviceCaps(desktop, DeviceCap.PLANES); + } + } + return Utility.s_bitDepth; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SafeDeleteFile(string path) + { + if (!string.IsNullOrEmpty(path)) + { + File.Delete(path); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SafeDeleteObject(ref IntPtr gdiObject) + { + IntPtr intPtr = gdiObject; + gdiObject = IntPtr.Zero; + if (IntPtr.Zero != intPtr) + { + NativeMethods.DeleteObject(intPtr); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SafeDestroyIcon(ref IntPtr hicon) + { + IntPtr intPtr = hicon; + hicon = IntPtr.Zero; + if (IntPtr.Zero != intPtr) + { + NativeMethods.DestroyIcon(intPtr); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SafeDestroyWindow(ref IntPtr hwnd) + { + IntPtr hwnd2 = hwnd; + hwnd = IntPtr.Zero; + if (NativeMethods.IsWindow(hwnd2)) + { + NativeMethods.DestroyWindow(hwnd2); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SafeDispose(ref T disposable) where T : IDisposable + { + IDisposable disposable2 = disposable; + disposable = default(T); + if (disposable2 != null) + { + disposable2.Dispose(); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SafeDisposeImage(ref IntPtr gdipImage) + { + IntPtr intPtr = gdipImage; + gdipImage = IntPtr.Zero; + if (IntPtr.Zero != intPtr) + { + NativeMethods.GdipDisposeImage(intPtr); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public static void SafeCoTaskMemFree(ref IntPtr ptr) + { + IntPtr intPtr = ptr; + ptr = IntPtr.Zero; + if (IntPtr.Zero != intPtr) + { + Marshal.FreeCoTaskMem(intPtr); + } + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void SafeFreeHGlobal(ref IntPtr hglobal) + { + IntPtr intPtr = hglobal; + hglobal = IntPtr.Zero; + if (IntPtr.Zero != intPtr) + { + Marshal.FreeHGlobal(intPtr); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public static void SafeRelease(ref T comObject) where T : class + { + T t = comObject; + comObject = default(T); + if (t != null) + { + Marshal.ReleaseComObject(t); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void GeneratePropertyString(StringBuilder source, string propertyName, string value) + { + if (source.Length != 0) + { + source.Append(' '); + } + source.Append(propertyName); + source.Append(": "); + if (string.IsNullOrEmpty(value)) + { + source.Append(""); + return; + } + source.Append('"'); + source.Append(value); + source.Append('"'); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [Obsolete] + public static string GenerateToString(T @object) where T : struct + { + StringBuilder stringBuilder = new StringBuilder(); + foreach (PropertyInfo propertyInfo in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public)) + { + if (stringBuilder.Length != 0) + { + stringBuilder.Append(", "); + } + object value = propertyInfo.GetValue(@object, null); + string format = (value == null) ? "{0}: " : "{0}: \"{1}\""; + stringBuilder.AppendFormat(format, propertyInfo.Name, value); + } + return stringBuilder.ToString(); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void CopyStream(Stream destination, Stream source) + { + destination.Position = 0L; + if (source.CanSeek) + { + source.Position = 0L; + destination.SetLength(source.Length); + } + byte[] array = new byte[4096]; + int num; + do + { + num = source.Read(array, 0, array.Length); + if (num != 0) + { + destination.Write(array, 0, num); + } + } + while (array.Length == num); + destination.Position = 0L; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static string HashStreamMD5(Stream stm) + { + stm.Position = 0L; + StringBuilder stringBuilder = new StringBuilder(); + using (MD5 md = MD5.Create()) + { + foreach (byte b in md.ComputeHash(stm)) + { + stringBuilder.Append(b.ToString("x2", CultureInfo.InvariantCulture)); + } + } + return stringBuilder.ToString(); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void EnsureDirectory(string path) + { + if (!Directory.Exists(Path.GetDirectoryName(path))) + { + Directory.CreateDirectory(Path.GetDirectoryName(path)); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static bool MemCmp(byte[] left, byte[] right, int cb) + { + GCHandle gchandle = GCHandle.Alloc(left, GCHandleType.Pinned); + IntPtr left2 = gchandle.AddrOfPinnedObject(); + GCHandle gchandle2 = GCHandle.Alloc(right, GCHandleType.Pinned); + IntPtr right2 = gchandle2.AddrOfPinnedObject(); + bool result = Utility._MemCmp(left2, right2, (long)cb); + gchandle.Free(); + gchandle2.Free(); + return result; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static string UrlDecode(string url) + { + if (url == null) + { + return null; + } + Utility._UrlDecoder urlDecoder = new Utility._UrlDecoder(url.Length, Encoding.UTF8); + int length = url.Length; + for (int i = 0; i < length; i++) + { + char c = url[i]; + if (c == '+') + { + urlDecoder.AddByte(32); + } + else + { + if (c == '%' && i < length - 2) + { + if (url[i + 1] == 'u' && i < length - 5) + { + int num = Utility._HexToInt(url[i + 2]); + int num2 = Utility._HexToInt(url[i + 3]); + int num3 = Utility._HexToInt(url[i + 4]); + int num4 = Utility._HexToInt(url[i + 5]); + if (num >= 0 && num2 >= 0 && num3 >= 0 && num4 >= 0) + { + urlDecoder.AddChar((char)(num << 12 | num2 << 8 | num3 << 4 | num4)); + i += 5; + goto IL_12D; + } + } + else + { + int num5 = Utility._HexToInt(url[i + 1]); + int num6 = Utility._HexToInt(url[i + 2]); + if (num5 >= 0 && num6 >= 0) + { + urlDecoder.AddByte((byte)(num5 << 4 | num6)); + i += 2; + goto IL_12D; + } + } + } + if ((c & 'タ') == '\0') + { + urlDecoder.AddByte((byte)c); + } + else + { + urlDecoder.AddChar(c); + } + } + IL_12D:; + } + return urlDecoder.GetString(); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static string UrlEncode(string url) + { + if (url == null) + { + return null; + } + byte[] array = Encoding.UTF8.GetBytes(url); + bool flag = false; + int num = 0; + foreach (byte b in array) + { + if (b == 32) + { + flag = true; + } + else if (!Utility._UrlEncodeIsSafe(b)) + { + num++; + flag = true; + } + } + if (flag) + { + byte[] array3 = new byte[array.Length + num * 2]; + int num2 = 0; + foreach (byte b2 in array) + { + if (Utility._UrlEncodeIsSafe(b2)) + { + array3[num2++] = b2; + } + else if (b2 == 32) + { + array3[num2++] = 43; + } + else + { + array3[num2++] = 37; + array3[num2++] = Utility._IntToHex(b2 >> 4 & 15); + array3[num2++] = Utility._IntToHex((int)(b2 & 15)); + } + } + array = array3; + } + return Encoding.ASCII.GetString(array); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + private static bool _UrlEncodeIsSafe(byte b) + { + if (Utility._IsAsciiAlphaNumeric(b)) + { + return true; + } + if (b != 33) + { + switch (b) + { + case 39: + case 40: + case 41: + case 42: + case 45: + case 46: + return true; + case 43: + case 44: + break; + default: + if (b == 95) + { + return true; + } + break; + } + return false; + } + return true; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + private static bool _IsAsciiAlphaNumeric(byte b) + { + return (b >= 97 && b <= 122) || (b >= 65 && b <= 90) || (b >= 48 && b <= 57); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + private static byte _IntToHex(int n) + { + if (n <= 9) + { + return (byte)(n + 48); + } + return (byte)(n - 10 + 65); + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + private static int _HexToInt(char h) + { + if (h >= '0' && h <= '9') + { + return (int)(h - '0'); + } + if (h >= 'a' && h <= 'f') + { + return (int)(h - 'a' + '\n'); + } + if (h >= 'A' && h <= 'F') + { + return (int)(h - 'A' + '\n'); + } + return -1; + } + + public static void AddDependencyPropertyChangeListener(object component, DependencyProperty property, EventHandler listener) + { + if (component == null) + { + return; + } + DependencyPropertyDescriptor dependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(property, component.GetType()); + dependencyPropertyDescriptor.AddValueChanged(component, listener); + } + + public static void RemoveDependencyPropertyChangeListener(object component, DependencyProperty property, EventHandler listener) + { + if (component == null) + { + return; + } + DependencyPropertyDescriptor dependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(property, component.GetType()); + dependencyPropertyDescriptor.RemoveValueChanged(component, listener); + } + + public static bool IsThicknessNonNegative(Thickness thickness) + { + return Utility.IsDoubleFiniteAndNonNegative(thickness.Top) && Utility.IsDoubleFiniteAndNonNegative(thickness.Left) && Utility.IsDoubleFiniteAndNonNegative(thickness.Bottom) && Utility.IsDoubleFiniteAndNonNegative(thickness.Right); + } + + public static bool IsCornerRadiusValid(CornerRadius cornerRadius) + { + return Utility.IsDoubleFiniteAndNonNegative(cornerRadius.TopLeft) && Utility.IsDoubleFiniteAndNonNegative(cornerRadius.TopRight) && Utility.IsDoubleFiniteAndNonNegative(cornerRadius.BottomLeft) && Utility.IsDoubleFiniteAndNonNegative(cornerRadius.BottomRight); + } + + public static bool IsDoubleFiniteAndNonNegative(double d) + { + return !double.IsNaN(d) && !double.IsInfinity(d) && d >= 0.0; + } + + private static readonly Version _osVersion = Environment.OSVersion.Version; + + private static readonly Version _presentationFrameworkVersion = Assembly.GetAssembly(typeof(Window)).GetName().Version; + + private static int s_bitDepth; + + private class _UrlDecoder + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public _UrlDecoder(int size, Encoding encoding) + { + this._encoding = encoding; + this._charBuffer = new char[size]; + this._byteBuffer = new byte[size]; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public void AddByte(byte b) + { + this._byteBuffer[this._byteCount++] = b; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public void AddChar(char ch) + { + this._FlushBytes(); + this._charBuffer[this._charCount++] = ch; + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + private void _FlushBytes() + { + if (this._byteCount > 0) + { + this._charCount += this._encoding.GetChars(this._byteBuffer, 0, this._byteCount, this._charBuffer, this._charCount); + this._byteCount = 0; + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public string GetString() + { + this._FlushBytes(); + if (this._charCount > 0) + { + return new string(this._charBuffer, 0, this._charCount); + } + return ""; + } + + private readonly Encoding _encoding; + + private readonly char[] _charBuffer; + + private readonly byte[] _byteBuffer; + + private int _byteCount; + + private int _charCount; + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs b/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs new file mode 100644 index 00000000..3c60c625 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs @@ -0,0 +1,246 @@ +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.IO; +using System.Threading; + +namespace Standard +{ + internal static class Verify + { + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DebuggerStepThrough] + public static void IsApartmentState(ApartmentState requiredState, string message) + { + if (Thread.CurrentThread.GetApartmentState() != requiredState) + { + throw new InvalidOperationException(message); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1820:TestForEmptyStringsUsingStringLength")] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void IsNeitherNullNorEmpty(string value, string name) + { + if (value == null) + { + throw new ArgumentNullException(name, "The parameter can not be either null or empty."); + } + if ("" == value) + { + throw new ArgumentException("The parameter can not be either null or empty.", name); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [SuppressMessage("Microsoft.Performance", "CA1820:TestForEmptyStringsUsingStringLength")] + [DebuggerStepThrough] + public static void IsNeitherNullNorWhitespace(string value, string name) + { + if (value == null) + { + throw new ArgumentNullException(name, "The parameter can not be either null or empty or consist only of white space characters."); + } + if ("" == value.Trim()) + { + throw new ArgumentException("The parameter can not be either null or empty or consist only of white space characters.", name); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DebuggerStepThrough] + public static void IsNotDefault(T obj, string name) where T : struct + { + T t = default(T); + if (t.Equals(obj)) + { + throw new ArgumentException("The parameter must not be the default value.", name); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void IsNotNull(T obj, string name) where T : class + { + if (obj == null) + { + throw new ArgumentNullException(name); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DebuggerStepThrough] + public static void IsNull(T obj, string name) where T : class + { + if (obj != null) + { + throw new ArgumentException("The parameter must be null.", name); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void PropertyIsNotNull(T obj, string name) where T : class + { + if (obj == null) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} cannot be null at this time.", new object[] + { + name + })); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void PropertyIsNull(T obj, string name) where T : class + { + if (obj != null) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} must be null at this time.", new object[] + { + name + })); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DebuggerStepThrough] + public static void IsTrue(bool statement, string name) + { + if (!statement) + { + throw new ArgumentException("", name); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void IsTrue(bool statement, string name, string message) + { + if (!statement) + { + throw new ArgumentException(message, name); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void AreEqual(T expected, T actual, string parameterName, string message) + { + if (expected == null) + { + if (actual != null && !actual.Equals(expected)) + { + throw new ArgumentException(message, parameterName); + } + } + else if (!expected.Equals(actual)) + { + throw new ArgumentException(message, parameterName); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void AreNotEqual(T notExpected, T actual, string parameterName, string message) + { + if (notExpected == null) + { + if (actual == null || actual.Equals(notExpected)) + { + throw new ArgumentException(message, parameterName); + } + } + else if (notExpected.Equals(actual)) + { + throw new ArgumentException(message, parameterName); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void UriIsAbsolute(Uri uri, string parameterName) + { + Verify.IsNotNull(uri, parameterName); + if (!uri.IsAbsoluteUri) + { + throw new ArgumentException("The URI must be absolute.", parameterName); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DebuggerStepThrough] + public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName) + { + if (value < lowerBoundInclusive || value >= upperBoundExclusive) + { + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The integer value must be bounded with [{0}, {1})", new object[] + { + lowerBoundInclusive, + upperBoundExclusive + }), parameterName); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive, string message, string parameter) + { + if (value < lowerBoundInclusive || value > upperBoundInclusive) + { + throw new ArgumentException(message, parameter); + } + } + + [DebuggerStepThrough] + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public static void TypeSupportsInterface(Type type, Type interfaceType, string parameterName) + { + Verify.IsNotNull(type, "type"); + Verify.IsNotNull(interfaceType, "interfaceType"); + if (type.GetInterface(interfaceType.Name) == null) + { + throw new ArgumentException("The type of this parameter does not support a required interface", parameterName); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DebuggerStepThrough] + public static void FileExists(string filePath, string parameterName) + { + Verify.IsNeitherNullNorEmpty(filePath, parameterName); + if (!File.Exists(filePath)) + { + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "No file exists at \"{0}\"", new object[] + { + filePath + }), parameterName); + } + } + + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [DebuggerStepThrough] + internal static void ImplementsInterface(object parameter, Type interfaceType, string parameterName) + { + bool flag = false; + foreach (Type left in parameter.GetType().GetInterfaces()) + { + if (left == interfaceType) + { + flag = true; + break; + } + } + if (!flag) + { + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The parameter must implement interface {0}.", new object[] + { + interfaceType.ToString() + }), parameterName); + } + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WIN32_FIND_DATAW.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WIN32_FIND_DATAW.cs new file mode 100644 index 00000000..62ab3a7f --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WIN32_FIND_DATAW.cs @@ -0,0 +1,36 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +namespace Standard +{ + [BestFitMapping(false)] + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + internal class WIN32_FIND_DATAW + { + public FileAttributes dwFileAttributes; + + public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime; + + public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime; + + public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime; + + public int nFileSizeHigh; + + public int nFileSizeLow; + + public int dwReserved0; + + public int dwReserved1; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] + public string cFileName; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)] + public string cAlternateFileName; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWPLACEMENT.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWPLACEMENT.cs new file mode 100644 index 00000000..b121d09a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWPLACEMENT.cs @@ -0,0 +1,21 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential)] + internal class WINDOWPLACEMENT + { + public int length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); + + public int flags; + + public SW showCmd; + + public POINT ptMinPosition; + + public POINT ptMaxPosition; + + public RECT rcNormalPosition; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWPOS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWPOS.cs new file mode 100644 index 00000000..282b504f --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWPOS.cs @@ -0,0 +1,21 @@ +using System; + +namespace Standard +{ + internal struct WINDOWPOS + { + public IntPtr hwnd; + + public IntPtr hwndInsertAfter; + + public int x; + + public int y; + + public int cx; + + public int cy; + + public int flags; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWTHEMEATTRIBUTETYPE.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWTHEMEATTRIBUTETYPE.cs new file mode 100644 index 00000000..3aea556e --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WINDOWTHEMEATTRIBUTETYPE.cs @@ -0,0 +1,9 @@ +using System; + +namespace Standard +{ + internal enum WINDOWTHEMEATTRIBUTETYPE : uint + { + WTA_NONCLIENT = 1u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WM.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WM.cs new file mode 100644 index 00000000..38e0077d --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WM.cs @@ -0,0 +1,139 @@ +using System; + +namespace Standard +{ + internal enum WM + { + NULL, + CREATE, + DESTROY, + MOVE, + SIZE = 5, + ACTIVATE, + SETFOCUS, + KILLFOCUS, + ENABLE = 10, + SETREDRAW, + SETTEXT, + GETTEXT, + GETTEXTLENGTH, + PAINT, + CLOSE, + QUERYENDSESSION, + QUIT, + QUERYOPEN, + ERASEBKGND, + SYSCOLORCHANGE, + SHOWWINDOW = 24, + CTLCOLOR, + WININICHANGE, + SETTINGCHANGE = 26, + ACTIVATEAPP = 28, + SETCURSOR = 32, + MOUSEACTIVATE, + CHILDACTIVATE, + QUEUESYNC, + GETMINMAXINFO, + WINDOWPOSCHANGING = 70, + WINDOWPOSCHANGED, + CONTEXTMENU = 123, + STYLECHANGING, + STYLECHANGED, + DISPLAYCHANGE, + GETICON, + SETICON, + NCCREATE, + NCDESTROY, + NCCALCSIZE, + NCHITTEST, + NCPAINT, + NCACTIVATE, + GETDLGCODE, + SYNCPAINT, + NCMOUSEMOVE = 160, + NCLBUTTONDOWN, + NCLBUTTONUP, + NCLBUTTONDBLCLK, + NCRBUTTONDOWN, + NCRBUTTONUP, + NCRBUTTONDBLCLK, + NCMBUTTONDOWN, + NCMBUTTONUP, + NCMBUTTONDBLCLK, + SYSKEYDOWN = 260, + SYSKEYUP, + SYSCHAR, + SYSDEADCHAR, + COMMAND = 273, + SYSCOMMAND, + MOUSEMOVE = 512, + LBUTTONDOWN, + LBUTTONUP, + LBUTTONDBLCLK, + RBUTTONDOWN, + RBUTTONUP, + RBUTTONDBLCLK, + MBUTTONDOWN, + MBUTTONUP, + MBUTTONDBLCLK, + MOUSEWHEEL, + XBUTTONDOWN, + XBUTTONUP, + XBUTTONDBLCLK, + MOUSEHWHEEL, + PARENTNOTIFY = 528, + CAPTURECHANGED = 533, + POWERBROADCAST = 536, + DEVICECHANGE, + ENTERSIZEMOVE = 561, + EXITSIZEMOVE, + IME_SETCONTEXT = 641, + IME_NOTIFY, + IME_CONTROL, + IME_COMPOSITIONFULL, + IME_SELECT, + IME_CHAR, + IME_REQUEST = 648, + IME_KEYDOWN = 656, + IME_KEYUP, + NCMOUSELEAVE = 674, + TABLET_DEFBASE = 704, + TABLET_ADDED = 712, + TABLET_DELETED, + TABLET_FLICK = 715, + TABLET_QUERYSYSTEMGESTURESTATUS, + CUT = 768, + COPY, + PASTE, + CLEAR, + UNDO, + RENDERFORMAT, + RENDERALLFORMATS, + DESTROYCLIPBOARD, + DRAWCLIPBOARD, + PAINTCLIPBOARD, + VSCROLLCLIPBOARD, + SIZECLIPBOARD, + ASKCBFORMATNAME, + CHANGECBCHAIN, + HSCROLLCLIPBOARD, + QUERYNEWPALETTE, + PALETTEISCHANGING, + PALETTECHANGED, + HOTKEY, + PRINT = 791, + PRINTCLIENT, + APPCOMMAND, + THEMECHANGED, + DWMCOMPOSITIONCHANGED = 798, + DWMNCRENDERINGCHANGED, + DWMCOLORIZATIONCOLORCHANGED, + DWMWINDOWMAXIMIZEDCHANGE, + GETTITLEBARINFOEX = 831, + DWMSENDICONICTHUMBNAIL = 803, + DWMSENDICONICLIVEPREVIEWBITMAP = 806, + USER = 1024, + TRAYMOUSEMESSAGE = 2048, + APP = 32768 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WNDCLASSEX.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WNDCLASSEX.cs new file mode 100644 index 00000000..24ef66cb --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WNDCLASSEX.cs @@ -0,0 +1,35 @@ +using System; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + internal struct WNDCLASSEX + { + public int cbSize; + + public CS style; + + public WndProc lpfnWndProc; + + public int cbClsExtra; + + public int cbWndExtra; + + public IntPtr hInstance; + + public IntPtr hIcon; + + public IntPtr hCursor; + + public IntPtr hbrBackground; + + [MarshalAs(UnmanagedType.LPWStr)] + public string lpszMenuName; + + [MarshalAs(UnmanagedType.LPWStr)] + public string lpszClassName; + + public IntPtr hIconSm; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WS.cs new file mode 100644 index 00000000..33745706 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WS.cs @@ -0,0 +1,36 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum WS : uint + { + OVERLAPPED = 0u, + POPUP = 2147483648u, + CHILD = 1073741824u, + MINIMIZE = 536870912u, + VISIBLE = 268435456u, + DISABLED = 134217728u, + CLIPSIBLINGS = 67108864u, + CLIPCHILDREN = 33554432u, + MAXIMIZE = 16777216u, + BORDER = 8388608u, + DLGFRAME = 4194304u, + VSCROLL = 2097152u, + HSCROLL = 1048576u, + SYSMENU = 524288u, + THICKFRAME = 262144u, + GROUP = 131072u, + TABSTOP = 65536u, + MINIMIZEBOX = 131072u, + MAXIMIZEBOX = 65536u, + CAPTION = 12582912u, + TILED = 0u, + ICONIC = 536870912u, + SIZEBOX = 262144u, + TILEDWINDOW = 13565952u, + OVERLAPPEDWINDOW = 13565952u, + POPUPWINDOW = 2156396544u, + CHILDWINDOW = 1073741824u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WS_EX.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WS_EX.cs new file mode 100644 index 00000000..8a6ef563 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WS_EX.cs @@ -0,0 +1,36 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum WS_EX : uint + { + None = 0u, + DLGMODALFRAME = 1u, + NOPARENTNOTIFY = 4u, + TOPMOST = 8u, + ACCEPTFILES = 16u, + TRANSPARENT = 32u, + MDICHILD = 64u, + TOOLWINDOW = 128u, + WINDOWEDGE = 256u, + CLIENTEDGE = 512u, + CONTEXTHELP = 1024u, + RIGHT = 4096u, + LEFT = 0u, + RTLREADING = 8192u, + LTRREADING = 0u, + LEFTSCROLLBAR = 16384u, + RIGHTSCROLLBAR = 0u, + CONTROLPARENT = 65536u, + STATICEDGE = 131072u, + APPWINDOW = 262144u, + LAYERED = 524288u, + NOINHERITLAYOUT = 1048576u, + LAYOUTRTL = 4194304u, + COMPOSITED = 33554432u, + NOACTIVATE = 134217728u, + OVERLAPPEDWINDOW = 768u, + PALETTEWINDOW = 392u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WTA_OPTIONS.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WTA_OPTIONS.cs new file mode 100644 index 00000000..efb3cf04 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WTA_OPTIONS.cs @@ -0,0 +1,20 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Explicit)] + internal struct WTA_OPTIONS + { + public const uint Size = 8u; + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification = "Used by native code.")] + [FieldOffset(0)] + public WTNCA dwFlags; + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Justification = "Used by native code.")] + [FieldOffset(4)] + public WTNCA dwMask; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WTNCA.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WTNCA.cs new file mode 100644 index 00000000..bb1c19cc --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WTNCA.cs @@ -0,0 +1,14 @@ +using System; + +namespace Standard +{ + [Flags] + internal enum WTNCA : uint + { + NODRAWCAPTION = 1u, + NODRAWICON = 2u, + NOSYSMENU = 4u, + NOMIRRORHELP = 8u, + VALIDBITS = 15u + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WVR.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WVR.cs new file mode 100644 index 00000000..175cf689 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WVR.cs @@ -0,0 +1,16 @@ +using System; + +namespace Standard +{ + internal enum WVR + { + ALIGNTOP = 16, + ALIGNLEFT = 32, + ALIGNBOTTOM = 64, + ALIGNRIGHT = 128, + HREDRAW = 256, + VREDRAW = 512, + VALIDRECTS = 1024, + REDRAW = 768 + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/Win32Error.cs b/src/Shared/Microsoft.Windows.Shell/Standard/Win32Error.cs new file mode 100644 index 00000000..983a9cd2 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/Win32Error.cs @@ -0,0 +1,127 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; + +namespace Standard +{ + [StructLayout(LayoutKind.Explicit)] + internal struct Win32Error + { + public Win32Error(int i) + { + this._value = i; + } + + public static explicit operator HRESULT(Win32Error error) + { + if (error._value <= 0) + { + return new HRESULT((uint)error._value); + } + return HRESULT.Make(true, Facility.Win32, error._value & 65535); + } + + public HRESULT ToHRESULT() + { + return (HRESULT)this; + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + public static Win32Error GetLastError() + { + return new Win32Error(Marshal.GetLastWin32Error()); + } + + public override bool Equals(object obj) + { + bool result; + try + { + result = (((Win32Error)obj)._value == this._value); + } + catch (InvalidCastException) + { + result = false; + } + return result; + } + + public override int GetHashCode() + { + return this._value.GetHashCode(); + } + + public static bool operator ==(Win32Error errLeft, Win32Error errRight) + { + return errLeft._value == errRight._value; + } + + public static bool operator !=(Win32Error errLeft, Win32Error errRight) + { + return !(errLeft == errRight); + } + + [FieldOffset(0)] + private readonly int _value; + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_SUCCESS = new Win32Error(0); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_INVALID_FUNCTION = new Win32Error(1); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_FILE_NOT_FOUND = new Win32Error(2); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_PATH_NOT_FOUND = new Win32Error(3); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_TOO_MANY_OPEN_FILES = new Win32Error(4); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_ACCESS_DENIED = new Win32Error(5); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_INVALID_HANDLE = new Win32Error(6); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_OUTOFMEMORY = new Win32Error(14); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_NO_MORE_FILES = new Win32Error(18); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_SHARING_VIOLATION = new Win32Error(32); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_INVALID_PARAMETER = new Win32Error(87); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_INSUFFICIENT_BUFFER = new Win32Error(122); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_NESTING_NOT_ALLOWED = new Win32Error(215); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_KEY_DELETED = new Win32Error(1018); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_NOT_FOUND = new Win32Error(1168); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_NO_MATCH = new Win32Error(1169); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_BAD_DEVICE = new Win32Error(1200); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_CANCELLED = new Win32Error(1223); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_CLASS_ALREADY_EXISTS = new Win32Error(1410); + + [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] + public static readonly Win32Error ERROR_INVALID_DATATYPE = new Win32Error(1804); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/Win32Value.cs b/src/Shared/Microsoft.Windows.Shell/Standard/Win32Value.cs new file mode 100644 index 00000000..3066201a --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/Win32Value.cs @@ -0,0 +1,21 @@ +using System; + +namespace Standard +{ + internal static class Win32Value + { + public const uint MAX_PATH = 260u; + + public const uint INFOTIPSIZE = 1024u; + + public const uint TRUE = 1u; + + public const uint FALSE = 0u; + + public const uint sizeof_WCHAR = 2u; + + public const uint sizeof_CHAR = 1u; + + public const uint sizeof_BOOL = 4u; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WndProc.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WndProc.cs new file mode 100644 index 00000000..788859ce --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WndProc.cs @@ -0,0 +1,6 @@ +using System; + +namespace Standard +{ + internal delegate IntPtr WndProc(IntPtr hwnd, WM uMsg, IntPtr wParam, IntPtr lParam); +} diff --git a/src/Shared/Microsoft.Windows.Shell/Standard/WndProcHook.cs b/src/Shared/Microsoft.Windows.Shell/Standard/WndProcHook.cs new file mode 100644 index 00000000..4f2269bf --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/Standard/WndProcHook.cs @@ -0,0 +1,6 @@ +using System; + +namespace Standard +{ + internal delegate IntPtr WndProcHook(IntPtr hwnd, WM uMsg, IntPtr wParam, IntPtr lParam, ref bool handled); +} diff --git a/src/Shared/Microsoft.Windows.Shell/SystemCommands.cs b/src/Shared/Microsoft.Windows.Shell/SystemCommands.cs new file mode 100644 index 00000000..1e12892c --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/SystemCommands.cs @@ -0,0 +1,77 @@ +using System; +using System.Windows; +using System.Windows.Input; +using System.Windows.Interop; +using Standard; + +namespace Microsoft.Windows.Shell +{ + public static class SystemCommands + { + public static RoutedCommand CloseWindowCommand { get; private set; } = new RoutedCommand("CloseWindow", typeof(SystemCommands)); + + public static RoutedCommand MaximizeWindowCommand { get; private set; } = new RoutedCommand("MaximizeWindow", typeof(SystemCommands)); + + public static RoutedCommand MinimizeWindowCommand { get; private set; } = new RoutedCommand("MinimizeWindow", typeof(SystemCommands)); + + public static RoutedCommand RestoreWindowCommand { get; private set; } = new RoutedCommand("RestoreWindow", typeof(SystemCommands)); + + public static RoutedCommand ShowSystemMenuCommand { get; private set; } = new RoutedCommand("ShowSystemMenu", typeof(SystemCommands)); + + private static void _PostSystemCommand(Window window, SC command) + { + IntPtr handle = new WindowInteropHelper(window).Handle; + if (handle == IntPtr.Zero || !NativeMethods.IsWindow(handle)) + { + return; + } + NativeMethods.PostMessage(handle, WM.SYSCOMMAND, new IntPtr((int)command), IntPtr.Zero); + } + + public static void CloseWindow(Window window) + { + Verify.IsNotNull(window, "window"); + SystemCommands._PostSystemCommand(window, SC.CLOSE); + } + + public static void MaximizeWindow(Window window) + { + Verify.IsNotNull(window, "window"); + SystemCommands._PostSystemCommand(window, SC.MAXIMIZE); + } + + public static void MinimizeWindow(Window window) + { + Verify.IsNotNull(window, "window"); + SystemCommands._PostSystemCommand(window, SC.MINIMIZE); + } + + public static void RestoreWindow(Window window) + { + Verify.IsNotNull(window, "window"); + SystemCommands._PostSystemCommand(window, SC.RESTORE); + } + + public static void ShowSystemMenu(Window window, Point screenLocation) + { + Verify.IsNotNull(window, "window"); + SystemCommands.ShowSystemMenuPhysicalCoordinates(window, DpiHelper.LogicalPixelsToDevice(screenLocation)); + } + + internal static void ShowSystemMenuPhysicalCoordinates(Window window, Point physicalScreenLocation) + { + Verify.IsNotNull(window, "window"); + IntPtr handle = new WindowInteropHelper(window).Handle; + if (handle == IntPtr.Zero || !NativeMethods.IsWindow(handle)) + { + return; + } + IntPtr systemMenu = NativeMethods.GetSystemMenu(handle, false); + uint num = NativeMethods.TrackPopupMenuEx(systemMenu, 256u, (int)physicalScreenLocation.X, (int)physicalScreenLocation.Y, handle, IntPtr.Zero); + if (num != 0u) + { + NativeMethods.PostMessage(handle, WM.SYSCOMMAND, new IntPtr((long)((ulong)num)), IntPtr.Zero); + } + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/SystemParameters2.cs b/src/Shared/Microsoft.Windows.Shell/SystemParameters2.cs new file mode 100644 index 00000000..9fc0517c --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/SystemParameters2.cs @@ -0,0 +1,543 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Media; +using Standard; + +namespace Microsoft.Windows.Shell +{ + [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable")] + public class SystemParameters2 : INotifyPropertyChanged + { + private void _InitializeIsGlassEnabled() + { + this.IsGlassEnabled = NativeMethods.DwmIsCompositionEnabled(); + } + + private void _UpdateIsGlassEnabled(IntPtr wParam, IntPtr lParam) + { + this._InitializeIsGlassEnabled(); + } + + private void _InitializeGlassColor() + { + uint num; + bool flag; + NativeMethods.DwmGetColorizationColor(out num, out flag); + num |= (flag ? 4278190080u : 0u); + this.WindowGlassColor = Utility.ColorFromArgbDword(num); + SolidColorBrush solidColorBrush = new SolidColorBrush(this.WindowGlassColor); + solidColorBrush.Freeze(); + this.WindowGlassBrush = solidColorBrush; + } + + private void _UpdateGlassColor(IntPtr wParam, IntPtr lParam) + { + bool flag = lParam != IntPtr.Zero; + uint num = (uint)((int)wParam.ToInt64()); + num |= (flag ? 4278190080u : 0u); + this.WindowGlassColor = Utility.ColorFromArgbDword(num); + SolidColorBrush solidColorBrush = new SolidColorBrush(this.WindowGlassColor); + solidColorBrush.Freeze(); + this.WindowGlassBrush = solidColorBrush; + } + + private void _InitializeCaptionHeight() + { + Point devicePoint = new Point(0.0, (double)NativeMethods.GetSystemMetrics(SM.CYCAPTION)); + this.WindowCaptionHeight = DpiHelper.DevicePixelsToLogical(devicePoint).Y; + } + + private void _UpdateCaptionHeight(IntPtr wParam, IntPtr lParam) + { + this._InitializeCaptionHeight(); + } + + private void _InitializeWindowResizeBorderThickness() + { + Size deviceSize = new Size((double)NativeMethods.GetSystemMetrics(SM.CXFRAME), (double)NativeMethods.GetSystemMetrics(SM.CYFRAME)); + Size size = DpiHelper.DeviceSizeToLogical(deviceSize); + this.WindowResizeBorderThickness = new Thickness(size.Width, size.Height, size.Width, size.Height); + } + + private void _UpdateWindowResizeBorderThickness(IntPtr wParam, IntPtr lParam) + { + this._InitializeWindowResizeBorderThickness(); + } + + private void _InitializeWindowNonClientFrameThickness() + { + Size deviceSize = new Size((double)NativeMethods.GetSystemMetrics(SM.CXFRAME), (double)NativeMethods.GetSystemMetrics(SM.CYFRAME)); + Size size = DpiHelper.DeviceSizeToLogical(deviceSize); + int systemMetrics = NativeMethods.GetSystemMetrics(SM.CYCAPTION); + double y = DpiHelper.DevicePixelsToLogical(new Point(0.0, (double)systemMetrics)).Y; + this.WindowNonClientFrameThickness = new Thickness(size.Width, size.Height + y, size.Width, size.Height); + } + + private void _UpdateWindowNonClientFrameThickness(IntPtr wParam, IntPtr lParam) + { + this._InitializeWindowNonClientFrameThickness(); + } + + private void _InitializeSmallIconSize() + { + this.SmallIconSize = new Size((double)NativeMethods.GetSystemMetrics(SM.CXSMICON), (double)NativeMethods.GetSystemMetrics(SM.CYSMICON)); + } + + private void _UpdateSmallIconSize(IntPtr wParam, IntPtr lParam) + { + this._InitializeSmallIconSize(); + } + + private void _LegacyInitializeCaptionButtonLocation() + { + int systemMetrics = NativeMethods.GetSystemMetrics(SM.CXSIZE); + int systemMetrics2 = NativeMethods.GetSystemMetrics(SM.CYSIZE); + int num = NativeMethods.GetSystemMetrics(SM.CXFRAME) + NativeMethods.GetSystemMetrics(SM.CXEDGE); + int num2 = NativeMethods.GetSystemMetrics(SM.CYFRAME) + NativeMethods.GetSystemMetrics(SM.CYEDGE); + Rect windowCaptionButtonsLocation = new Rect(0.0, 0.0, (double)(systemMetrics * 3), (double)systemMetrics2); + windowCaptionButtonsLocation.Offset((double)(-(double)num) - windowCaptionButtonsLocation.Width, (double)num2); + this.WindowCaptionButtonsLocation = windowCaptionButtonsLocation; + } + + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] + private void _InitializeCaptionButtonLocation() + { + if (!Utility.IsOSVistaOrNewer || !NativeMethods.IsThemeActive()) + { + this._LegacyInitializeCaptionButtonLocation(); + return; + } + TITLEBARINFOEX titlebarinfoex = new TITLEBARINFOEX + { + cbSize = Marshal.SizeOf(typeof(TITLEBARINFOEX)) + }; + IntPtr intPtr = Marshal.AllocHGlobal(titlebarinfoex.cbSize); + try + { + Marshal.StructureToPtr(titlebarinfoex, intPtr, false); + NativeMethods.ShowWindow(this._messageHwnd.Handle, SW.SHOW); + NativeMethods.SendMessage(this._messageHwnd.Handle, WM.GETTITLEBARINFOEX, IntPtr.Zero, intPtr); + titlebarinfoex = (TITLEBARINFOEX)Marshal.PtrToStructure(intPtr, typeof(TITLEBARINFOEX)); + } + finally + { + NativeMethods.ShowWindow(this._messageHwnd.Handle, SW.HIDE); + Utility.SafeFreeHGlobal(ref intPtr); + } + RECT rect = RECT.Union(titlebarinfoex.rgrect_CloseButton, titlebarinfoex.rgrect_MinimizeButton); + RECT windowRect = NativeMethods.GetWindowRect(this._messageHwnd.Handle); + Rect deviceRectangle = new Rect((double)(rect.Left - windowRect.Width - windowRect.Left), (double)(rect.Top - windowRect.Top), (double)rect.Width, (double)rect.Height); + Rect windowCaptionButtonsLocation = DpiHelper.DeviceRectToLogical(deviceRectangle); + this.WindowCaptionButtonsLocation = windowCaptionButtonsLocation; + } + + private void _UpdateCaptionButtonLocation(IntPtr wParam, IntPtr lParam) + { + this._InitializeCaptionButtonLocation(); + } + + private void _InitializeHighContrast() + { + this.HighContrast = ((NativeMethods.SystemParameterInfo_GetHIGHCONTRAST().dwFlags & HCF.HIGHCONTRASTON) != (HCF)0); + } + + private void _UpdateHighContrast(IntPtr wParam, IntPtr lParam) + { + this._InitializeHighContrast(); + } + + private void _InitializeThemeInfo() + { + if (!NativeMethods.IsThemeActive()) + { + this.UxThemeName = "Classic"; + this.UxThemeColor = ""; + return; + } + string path; + string uxThemeColor; + string text; + NativeMethods.GetCurrentThemeName(out path, out uxThemeColor, out text); + this.UxThemeName = Path.GetFileNameWithoutExtension(path); + this.UxThemeColor = uxThemeColor; + } + + private void _UpdateThemeInfo(IntPtr wParam, IntPtr lParam) + { + this._InitializeThemeInfo(); + } + + private void _InitializeWindowCornerRadius() + { + CornerRadius windowCornerRadius = default(CornerRadius); + string a; + if ((a = this.UxThemeName.ToUpperInvariant()) != null) + { + if (a == "LUNA") + { + windowCornerRadius = new CornerRadius(6.0, 6.0, 0.0, 0.0); + goto IL_E6; + } + if (!(a == "AERO")) + { + if (!(a == "CLASSIC") && !(a == "ZUNE") && !(a == "ROYALE")) + { + } + } + else + { + if (NativeMethods.DwmIsCompositionEnabled()) + { + windowCornerRadius = new CornerRadius(8.0); + goto IL_E6; + } + windowCornerRadius = new CornerRadius(6.0, 6.0, 0.0, 0.0); + goto IL_E6; + } + } + windowCornerRadius = new CornerRadius(0.0); + IL_E6: + this.WindowCornerRadius = windowCornerRadius; + } + + private void _UpdateWindowCornerRadius(IntPtr wParam, IntPtr lParam) + { + this._InitializeWindowCornerRadius(); + } + + private SystemParameters2() + { + this._messageHwnd = new MessageWindow((CS)0u, WS.DISABLED | WS.BORDER | WS.DLGFRAME | WS.SYSMENU | WS.THICKFRAME | WS.GROUP | WS.TABSTOP, WS_EX.None, new Rect(-16000.0, -16000.0, 100.0, 100.0), "", new WndProc(this._WndProc)); + this._messageHwnd.Dispatcher.ShutdownStarted += delegate(object sender, EventArgs e) + { + Utility.SafeDispose(ref this._messageHwnd); + }; + this._InitializeIsGlassEnabled(); + this._InitializeGlassColor(); + this._InitializeCaptionHeight(); + this._InitializeWindowNonClientFrameThickness(); + this._InitializeWindowResizeBorderThickness(); + this._InitializeCaptionButtonLocation(); + this._InitializeSmallIconSize(); + this._InitializeHighContrast(); + this._InitializeThemeInfo(); + this._InitializeWindowCornerRadius(); + this._UpdateTable = new Dictionary> + { + { + WM.THEMECHANGED, + new List + { + new SystemParameters2._SystemMetricUpdate(this._UpdateThemeInfo), + new SystemParameters2._SystemMetricUpdate(this._UpdateHighContrast), + new SystemParameters2._SystemMetricUpdate(this._UpdateWindowCornerRadius), + new SystemParameters2._SystemMetricUpdate(this._UpdateCaptionButtonLocation) + } + }, + { + WM.WININICHANGE, + new List + { + new SystemParameters2._SystemMetricUpdate(this._UpdateCaptionHeight), + new SystemParameters2._SystemMetricUpdate(this._UpdateWindowResizeBorderThickness), + new SystemParameters2._SystemMetricUpdate(this._UpdateSmallIconSize), + new SystemParameters2._SystemMetricUpdate(this._UpdateHighContrast), + new SystemParameters2._SystemMetricUpdate(this._UpdateWindowNonClientFrameThickness), + new SystemParameters2._SystemMetricUpdate(this._UpdateCaptionButtonLocation) + } + }, + { + WM.DWMNCRENDERINGCHANGED, + new List + { + new SystemParameters2._SystemMetricUpdate(this._UpdateIsGlassEnabled) + } + }, + { + WM.DWMCOMPOSITIONCHANGED, + new List + { + new SystemParameters2._SystemMetricUpdate(this._UpdateIsGlassEnabled) + } + }, + { + WM.DWMCOLORIZATIONCOLORCHANGED, + new List + { + new SystemParameters2._SystemMetricUpdate(this._UpdateGlassColor) + } + } + }; + } + + public static SystemParameters2 Current + { + get + { + if (SystemParameters2._threadLocalSingleton == null) + { + SystemParameters2._threadLocalSingleton = new SystemParameters2(); + } + return SystemParameters2._threadLocalSingleton; + } + } + + private IntPtr _WndProc(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam) + { + List list; + if (this._UpdateTable != null && this._UpdateTable.TryGetValue(msg, out list)) + { + foreach (SystemParameters2._SystemMetricUpdate systemMetricUpdate in list) + { + systemMetricUpdate(wParam, lParam); + } + } + return NativeMethods.DefWindowProc(hwnd, msg, wParam, lParam); + } + + public bool IsGlassEnabled + { + get + { + return NativeMethods.DwmIsCompositionEnabled(); + } + private set + { + if (value != this._isGlassEnabled) + { + this._isGlassEnabled = value; + this._NotifyPropertyChanged("IsGlassEnabled"); + } + } + } + + public Color WindowGlassColor + { + get + { + return this._glassColor; + } + private set + { + if (value != this._glassColor) + { + this._glassColor = value; + this._NotifyPropertyChanged("WindowGlassColor"); + } + } + } + + public SolidColorBrush WindowGlassBrush + { + get + { + return this._glassColorBrush; + } + private set + { + if (this._glassColorBrush == null || value.Color != this._glassColorBrush.Color) + { + this._glassColorBrush = value; + this._NotifyPropertyChanged("WindowGlassBrush"); + } + } + } + + public Thickness WindowResizeBorderThickness + { + get + { + return this._windowResizeBorderThickness; + } + private set + { + if (value != this._windowResizeBorderThickness) + { + this._windowResizeBorderThickness = value; + this._NotifyPropertyChanged("WindowResizeBorderThickness"); + } + } + } + + public Thickness WindowNonClientFrameThickness + { + get + { + return this._windowNonClientFrameThickness; + } + private set + { + if (value != this._windowNonClientFrameThickness) + { + this._windowNonClientFrameThickness = value; + this._NotifyPropertyChanged("WindowNonClientFrameThickness"); + } + } + } + + public double WindowCaptionHeight + { + get + { + return this._captionHeight; + } + private set + { + if (value != this._captionHeight) + { + this._captionHeight = value; + this._NotifyPropertyChanged("WindowCaptionHeight"); + } + } + } + + public Size SmallIconSize + { + get + { + return new Size(this._smallIconSize.Width, this._smallIconSize.Height); + } + private set + { + if (value != this._smallIconSize) + { + this._smallIconSize = value; + this._NotifyPropertyChanged("SmallIconSize"); + } + } + } + + [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Ux")] + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ux")] + public string UxThemeName + { + get + { + return this._uxThemeName; + } + private set + { + if (value != this._uxThemeName) + { + this._uxThemeName = value; + this._NotifyPropertyChanged("UxThemeName"); + } + } + } + + [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Ux")] + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ux")] + public string UxThemeColor + { + get + { + return this._uxThemeColor; + } + private set + { + if (value != this._uxThemeColor) + { + this._uxThemeColor = value; + this._NotifyPropertyChanged("UxThemeColor"); + } + } + } + + public bool HighContrast + { + get + { + return this._isHighContrast; + } + private set + { + if (value != this._isHighContrast) + { + this._isHighContrast = value; + this._NotifyPropertyChanged("HighContrast"); + } + } + } + + public CornerRadius WindowCornerRadius + { + get + { + return this._windowCornerRadius; + } + private set + { + if (value != this._windowCornerRadius) + { + this._windowCornerRadius = value; + this._NotifyPropertyChanged("WindowCornerRadius"); + } + } + } + + public Rect WindowCaptionButtonsLocation + { + get + { + return this._captionButtonLocation; + } + private set + { + if (value != this._captionButtonLocation) + { + this._captionButtonLocation = value; + this._NotifyPropertyChanged("WindowCaptionButtonsLocation"); + } + } + } + + private void _NotifyPropertyChanged(string propertyName) + { + PropertyChangedEventHandler propertyChanged = this.PropertyChanged; + if (propertyChanged != null) + { + propertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [ThreadStatic] + private static SystemParameters2 _threadLocalSingleton; + + private MessageWindow _messageHwnd; + + private bool _isGlassEnabled; + + private Color _glassColor; + + private SolidColorBrush _glassColorBrush; + + private Thickness _windowResizeBorderThickness; + + private Thickness _windowNonClientFrameThickness; + + private double _captionHeight; + + private Size _smallIconSize; + + private string _uxThemeName; + + private string _uxThemeColor; + + private bool _isHighContrast; + + private CornerRadius _windowCornerRadius; + + private Rect _captionButtonLocation; + + private readonly Dictionary> _UpdateTable; + + private delegate void _SystemMetricUpdate(IntPtr wParam, IntPtr lParam); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/TaskbarItemInfo.cs b/src/Shared/Microsoft.Windows.Shell/TaskbarItemInfo.cs new file mode 100644 index 00000000..a3bfdbdb --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/TaskbarItemInfo.cs @@ -0,0 +1,639 @@ +using System; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Windows; +using System.Windows.Interop; +using System.Windows.Media; +using Standard; + +namespace Microsoft.Windows.Shell +{ + public sealed class TaskbarItemInfo : Freezable + { + protected override Freezable CreateInstanceCore() + { + return new TaskbarItemInfo(); + } + + [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] + public static TaskbarItemInfo GetTaskbarItemInfo(Window window) + { + Verify.IsNotNull(window, "window"); + return (TaskbarItemInfo)window.GetValue(TaskbarItemInfo.TaskbarItemInfoProperty); + } + + [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] + public static void SetTaskbarItemInfo(Window window, TaskbarItemInfo value) + { + Verify.IsNotNull(window, "window"); + window.SetValue(TaskbarItemInfo.TaskbarItemInfoProperty, value); + } + + private static void _OnTaskbarItemInfoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (DesignerProperties.GetIsInDesignMode(d)) + { + return; + } + Window window = (Window)d; + TaskbarItemInfo taskbarItemInfo = (TaskbarItemInfo)e.OldValue; + TaskbarItemInfo taskbarItemInfo2 = (TaskbarItemInfo)e.NewValue; + if (taskbarItemInfo == taskbarItemInfo2) + { + return; + } + if (!Utility.IsOSWindows7OrNewer) + { + return; + } + if (taskbarItemInfo != null && taskbarItemInfo._window != null) + { + taskbarItemInfo._DetachWindow(); + } + if (taskbarItemInfo2 != null) + { + taskbarItemInfo2._SetWindow(window); + } + } + + private static object _CoerceTaskbarItemInfoValue(DependencyObject d, object value) + { + if (DesignerProperties.GetIsInDesignMode(d)) + { + return value; + } + Verify.IsNotNull(d, "d"); + Window window = (Window)d; + TaskbarItemInfo taskbarItemInfo = (TaskbarItemInfo)value; + if (taskbarItemInfo != null && taskbarItemInfo._window != null && taskbarItemInfo._window != window) + { + throw new NotSupportedException(); + } + window.VerifyAccess(); + return taskbarItemInfo; + } + + public TaskbarItemProgressState ProgressState + { + get + { + return (TaskbarItemProgressState)base.GetValue(TaskbarItemInfo.ProgressStateProperty); + } + set + { + base.SetValue(TaskbarItemInfo.ProgressStateProperty, value); + } + } + + private void _OnProgressStateChanged() + { + if (!this._isAttached) + { + return; + } + this._UpdateProgressState(true); + } + + private static TaskbarItemProgressState _CoerceProgressState(TaskbarItemProgressState value) + { + switch (value) + { + case TaskbarItemProgressState.None: + case TaskbarItemProgressState.Indeterminate: + case TaskbarItemProgressState.Normal: + case TaskbarItemProgressState.Error: + case TaskbarItemProgressState.Paused: + break; + default: + value = TaskbarItemProgressState.None; + break; + } + return value; + } + + public double ProgressValue + { + get + { + return (double)base.GetValue(TaskbarItemInfo.ProgressValueProperty); + } + set + { + base.SetValue(TaskbarItemInfo.ProgressValueProperty, value); + } + } + + private void _OnProgressValueChanged() + { + if (!this._isAttached) + { + return; + } + this._UpdateProgressValue(true); + } + + private static double _CoerceProgressValue(double progressValue) + { + if (double.IsNaN(progressValue)) + { + progressValue = 0.0; + } + progressValue = Math.Max(progressValue, 0.0); + progressValue = Math.Min(1.0, progressValue); + return progressValue; + } + + public ImageSource Overlay + { + get + { + return (ImageSource)base.GetValue(TaskbarItemInfo.OverlayProperty); + } + set + { + base.SetValue(TaskbarItemInfo.OverlayProperty, value); + } + } + + private void _OnOverlayChanged() + { + if (!this._isAttached) + { + return; + } + this._UpdateOverlay(true); + } + + public string Description + { + get + { + return (string)base.GetValue(TaskbarItemInfo.DescriptionProperty); + } + set + { + base.SetValue(TaskbarItemInfo.DescriptionProperty, value); + } + } + + private void _OnDescriptionChanged() + { + if (!this._isAttached) + { + return; + } + this._UpdateTooltip(true); + } + + public Thickness ThumbnailClipMargin + { + get + { + return (Thickness)base.GetValue(TaskbarItemInfo.ThumbnailClipMarginProperty); + } + set + { + base.SetValue(TaskbarItemInfo.ThumbnailClipMarginProperty, value); + } + } + + private void _OnThumbnailClipMarginChanged() + { + if (!this._isAttached) + { + return; + } + this._UpdateThumbnailClipping(true); + } + + private static Thickness _CoerceThumbnailClipMargin(Thickness margin) + { + if (margin.Left < 0.0 || margin.Right < 0.0 || margin.Top < 0.0 || margin.Bottom < 0.0) + { + return TaskbarItemInfo._EmptyThickness; + } + return margin; + } + + [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")] + public ThumbButtonInfoCollection ThumbButtonInfos + { + get + { + return (ThumbButtonInfoCollection)base.GetValue(TaskbarItemInfo.ThumbButtonInfosProperty); + } + set + { + base.SetValue(TaskbarItemInfo.ThumbButtonInfosProperty, value); + } + } + + private void _OnThumbButtonsChanged() + { + if (!this._isAttached) + { + return; + } + this._UpdateThumbButtons(true); + } + + private IntPtr _GetHICONFromImageSource(ImageSource image, Size dimensions) + { + if (this._gdipToken == null) + { + this._gdipToken = SafeGdiplusStartupToken.Startup(); + } + return Utility.GenerateHICON(image, dimensions); + } + + public TaskbarItemInfo() + { + if (!DesignerProperties.GetIsInDesignMode(this)) + { + ITaskbarList taskbarList = null; + try + { + taskbarList = CLSID.CoCreateInstance("56FDF344-FD6D-11d0-958A-006097C9A090"); + taskbarList.HrInit(); + this._taskbarList = (taskbarList as ITaskbarList3); + taskbarList = null; + } + finally + { + Utility.SafeRelease(ref taskbarList); + } + this._overlaySize = new Size((double)NativeMethods.GetSystemMetrics(SM.CXSMICON), (double)NativeMethods.GetSystemMetrics(SM.CYSMICON)); + } + this.ThumbButtonInfos = new ThumbButtonInfoCollection(); + } + + private void _SetWindow(Window window) + { + if (window == null) + { + return; + } + this._window = window; + if (this._taskbarList == null) + { + return; + } + IntPtr handle = new WindowInteropHelper(this._window).Handle; + if (!(handle != IntPtr.Zero)) + { + this._window.SourceInitialized += this._OnWindowSourceInitialized; + return; + } + this._hwndSource = HwndSource.FromHwnd(handle); + this._hwndSource.AddHook(new HwndSourceHook(this._WndProc)); + this._OnIsAttachedChanged(true); + } + + private void _OnWindowSourceInitialized(object sender, EventArgs e) + { + this._window.SourceInitialized -= this._OnWindowSourceInitialized; + IntPtr handle = new WindowInteropHelper(this._window).Handle; + this._hwndSource = HwndSource.FromHwnd(handle); + this._hwndSource.AddHook(new HwndSourceHook(this._WndProc)); + MSGFLTINFO msgfltinfo; + NativeMethods.ChangeWindowMessageFilterEx(handle, TaskbarItemInfo.WM_TASKBARBUTTONCREATED, MSGFLT.ALLOW, out msgfltinfo); + NativeMethods.ChangeWindowMessageFilterEx(handle, WM.COMMAND, MSGFLT.ALLOW, out msgfltinfo); + } + + private IntPtr _WndProc(IntPtr hwnd, int uMsg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + if (uMsg == (int)TaskbarItemInfo.WM_TASKBARBUTTONCREATED) + { + this._OnIsAttachedChanged(true); + this._isAttached = true; + handled = false; + } + else if (uMsg != 5) + { + if (uMsg == 273 && Utility.HIWORD(wParam.ToInt32()) == 6144) + { + int index = Utility.LOWORD(wParam.ToInt32()); + this.ThumbButtonInfos[index].InvokeClick(); + handled = true; + } + } + else + { + this._UpdateThumbnailClipping(this._isAttached); + handled = false; + } + return IntPtr.Zero; + } + + private void _OnIsAttachedChanged(bool attached) + { + this._haveAddedButtons = false; + if (!attached && this._hwndSource == null) + { + return; + } + this._UpdateOverlay(attached); + this._UpdateProgressState(attached); + this._UpdateProgressValue(attached); + this._UpdateTooltip(attached); + this._UpdateThumbnailClipping(attached); + this._UpdateThumbButtons(attached); + if (!attached) + { + this._hwndSource = null; + } + } + + private void _DetachWindow() + { + this._window.SourceInitialized -= this._OnWindowSourceInitialized; + this._isAttached = false; + this._OnIsAttachedChanged(false); + this._window = null; + } + + private HRESULT _UpdateOverlay(bool attached) + { + ImageSource overlay = this.Overlay; + if (overlay == null || !attached) + { + return this._taskbarList.SetOverlayIcon(this._hwndSource.Handle, IntPtr.Zero, null); + } + IntPtr hIcon = IntPtr.Zero; + HRESULT result; + try + { + hIcon = this._GetHICONFromImageSource(overlay, this._overlaySize); + result = this._taskbarList.SetOverlayIcon(this._hwndSource.Handle, hIcon, null); + } + finally + { + Utility.SafeDestroyIcon(ref hIcon); + } + return result; + } + + private HRESULT _UpdateTooltip(bool attached) + { + string pszTip = this.Description ?? ""; + if (!attached) + { + pszTip = ""; + } + return this._taskbarList.SetThumbnailTooltip(this._hwndSource.Handle, pszTip); + } + + private HRESULT _UpdateProgressValue(bool attached) + { + if (!attached || this.ProgressState == TaskbarItemProgressState.None || this.ProgressState == TaskbarItemProgressState.Indeterminate) + { + return HRESULT.S_OK; + } + ulong ullCompleted = (ulong)(this.ProgressValue * 1000.0); + return this._taskbarList.SetProgressValue(this._hwndSource.Handle, ullCompleted, 1000UL); + } + + private HRESULT _UpdateProgressState(bool attached) + { + TaskbarItemProgressState progressState = this.ProgressState; + TBPF tbpFlags = TBPF.NOPROGRESS; + if (attached) + { + switch (progressState) + { + case TaskbarItemProgressState.None: + tbpFlags = TBPF.NOPROGRESS; + break; + case TaskbarItemProgressState.Indeterminate: + tbpFlags = TBPF.INDETERMINATE; + break; + case TaskbarItemProgressState.Normal: + tbpFlags = TBPF.NORMAL; + break; + case TaskbarItemProgressState.Error: + tbpFlags = TBPF.ERROR; + break; + case TaskbarItemProgressState.Paused: + tbpFlags = TBPF.PAUSED; + break; + default: + tbpFlags = TBPF.NOPROGRESS; + break; + } + } + HRESULT result = this._taskbarList.SetProgressState(this._hwndSource.Handle, tbpFlags); + if (result.Succeeded) + { + result = this._UpdateProgressValue(attached); + } + return result; + } + + private HRESULT _UpdateThumbnailClipping(bool attached) + { + RefRECT prcClip = null; + if (attached && this.ThumbnailClipMargin != TaskbarItemInfo._EmptyThickness) + { + Thickness thumbnailClipMargin = this.ThumbnailClipMargin; + RECT clientRect = NativeMethods.GetClientRect(this._hwndSource.Handle); + Rect rect = DpiHelper.DeviceRectToLogical(new Rect((double)clientRect.Left, (double)clientRect.Top, (double)clientRect.Width, (double)clientRect.Height)); + if (thumbnailClipMargin.Left + thumbnailClipMargin.Right >= rect.Width || thumbnailClipMargin.Top + thumbnailClipMargin.Bottom >= rect.Height) + { + prcClip = new RefRECT(0, 0, 0, 0); + } + else + { + Rect logicalRectangle = new Rect(thumbnailClipMargin.Left, thumbnailClipMargin.Top, rect.Width - thumbnailClipMargin.Left - thumbnailClipMargin.Right, rect.Height - thumbnailClipMargin.Top - thumbnailClipMargin.Bottom); + Rect rect2 = DpiHelper.LogicalRectToDevice(logicalRectangle); + prcClip = new RefRECT((int)rect2.Left, (int)rect2.Top, (int)rect2.Right, (int)rect2.Bottom); + } + } + return this._taskbarList.SetThumbnailClip(this._hwndSource.Handle, prcClip); + } + + private HRESULT _RegisterThumbButtons() + { + HRESULT hresult = HRESULT.S_OK; + if (!this._haveAddedButtons) + { + THUMBBUTTON[] array = new THUMBBUTTON[7]; + for (int i = 0; i < 7; i++) + { + array[i] = new THUMBBUTTON + { + iId = (uint)i, + dwFlags = (THBF.DISABLED | THBF.NOBACKGROUND | THBF.HIDDEN), + dwMask = (THB.ICON | THB.TOOLTIP | THB.FLAGS) + }; + } + hresult = this._taskbarList.ThumbBarAddButtons(this._hwndSource.Handle, (uint)array.Length, array); + if (hresult == HRESULT.E_INVALIDARG) + { + hresult = HRESULT.S_FALSE; + } + this._haveAddedButtons = hresult.Succeeded; + } + return hresult; + } + + private HRESULT _UpdateThumbButtons(bool attached) + { + THUMBBUTTON[] array = new THUMBBUTTON[7]; + HRESULT result = this._RegisterThumbButtons(); + if (result.Failed) + { + return result; + } + ThumbButtonInfoCollection thumbButtonInfos = this.ThumbButtonInfos; + HRESULT result2; + try + { + uint num = 0u; + if (!attached || thumbButtonInfos == null) + { + goto IL_1AE; + } + using (FreezableCollection.Enumerator enumerator = thumbButtonInfos.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + ThumbButtonInfo thumbButtonInfo = enumerator.Current; + THUMBBUTTON thumbbutton = new THUMBBUTTON + { + iId = num, + dwMask = (THB.ICON | THB.TOOLTIP | THB.FLAGS) + }; + switch (thumbButtonInfo.Visibility) + { + case Visibility.Visible: + goto IL_A5; + case Visibility.Hidden: + thumbbutton.dwFlags = (THBF.DISABLED | THBF.NOBACKGROUND); + thumbbutton.hIcon = IntPtr.Zero; + break; + case Visibility.Collapsed: + thumbbutton.dwFlags = THBF.HIDDEN; + break; + default: + goto IL_A5; + } + IL_146: + array[(int)((UIntPtr)num)] = thumbbutton; + num += 1u; + if (num != 7u) + { + continue; + } + break; + IL_A5: + thumbbutton.szTip = (thumbButtonInfo.Description ?? ""); + thumbbutton.hIcon = this._GetHICONFromImageSource(thumbButtonInfo.ImageSource, this._overlaySize); + if (!thumbButtonInfo.IsBackgroundVisible) + { + thumbbutton.dwFlags |= THBF.NOBACKGROUND; + } + if (!thumbButtonInfo.IsEnabled) + { + thumbbutton.dwFlags |= THBF.DISABLED; + } + else + { + thumbbutton.dwFlags = thumbbutton.dwFlags; + } + if (!thumbButtonInfo.IsInteractive) + { + thumbbutton.dwFlags |= THBF.NONINTERACTIVE; + } + if (thumbButtonInfo.DismissWhenClicked) + { + thumbbutton.dwFlags |= THBF.DISMISSONCLICK; + goto IL_146; + } + goto IL_146; + } + goto IL_1AE; + } + IL_179: + array[(int)((UIntPtr)num)] = new THUMBBUTTON + { + iId = num, + dwFlags = (THBF.DISABLED | THBF.NOBACKGROUND | THBF.HIDDEN), + dwMask = (THB.ICON | THB.TOOLTIP | THB.FLAGS) + }; + num += 1u; + IL_1AE: + if (num < 7u) + { + goto IL_179; + } + result2 = this._taskbarList.ThumbBarUpdateButtons(this._hwndSource.Handle, (uint)array.Length, array); + } + finally + { + foreach (THUMBBUTTON thumbbutton2 in array) + { + IntPtr hIcon = thumbbutton2.hIcon; + if (IntPtr.Zero != hIcon) + { + Utility.SafeDestroyIcon(ref hIcon); + } + } + } + return result2; + } + + private const int c_MaximumThumbButtons = 7; + + private static readonly WM WM_TASKBARBUTTONCREATED = NativeMethods.RegisterWindowMessage("TaskbarButtonCreated"); + + private static readonly Thickness _EmptyThickness = default(Thickness); + + private SafeGdiplusStartupToken _gdipToken; + + private bool _haveAddedButtons; + + private Window _window; + + private HwndSource _hwndSource; + + private ITaskbarList3 _taskbarList; + + private readonly Size _overlaySize; + + private bool _isAttached; + + public static readonly DependencyProperty TaskbarItemInfoProperty = DependencyProperty.RegisterAttached("TaskbarItemInfo", typeof(TaskbarItemInfo), typeof(TaskbarItemInfo), new PropertyMetadata(null, new PropertyChangedCallback(TaskbarItemInfo._OnTaskbarItemInfoChanged), new CoerceValueCallback(TaskbarItemInfo._CoerceTaskbarItemInfoValue))); + + public static readonly DependencyProperty ProgressStateProperty = DependencyProperty.Register("ProgressState", typeof(TaskbarItemProgressState), typeof(TaskbarItemInfo), new PropertyMetadata(TaskbarItemProgressState.None, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((TaskbarItemInfo)d)._OnProgressStateChanged(); + }, (DependencyObject d, object e) => TaskbarItemInfo._CoerceProgressState((TaskbarItemProgressState)e))); + + public static readonly DependencyProperty ProgressValueProperty = DependencyProperty.Register("ProgressValue", typeof(double), typeof(TaskbarItemInfo), new PropertyMetadata(0.0, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((TaskbarItemInfo)d)._OnProgressValueChanged(); + }, (DependencyObject d, object e) => TaskbarItemInfo._CoerceProgressValue((double)e))); + + public static readonly DependencyProperty OverlayProperty = DependencyProperty.Register("Overlay", typeof(ImageSource), typeof(TaskbarItemInfo), new PropertyMetadata(null, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((TaskbarItemInfo)d)._OnOverlayChanged(); + })); + + public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(TaskbarItemInfo), new PropertyMetadata(string.Empty, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((TaskbarItemInfo)d)._OnDescriptionChanged(); + })); + + public static readonly DependencyProperty ThumbnailClipMarginProperty = DependencyProperty.Register("ThumbnailClipMargin", typeof(Thickness), typeof(TaskbarItemInfo), new PropertyMetadata(default(Thickness), delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((TaskbarItemInfo)d)._OnThumbnailClipMarginChanged(); + }, (DependencyObject d, object e) => TaskbarItemInfo._CoerceThumbnailClipMargin((Thickness)e))); + + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Infos")] + public static readonly DependencyProperty ThumbButtonInfosProperty = DependencyProperty.Register("ThumbButtonInfos", typeof(ThumbButtonInfoCollection), typeof(TaskbarItemInfo), new PropertyMetadata(null, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((TaskbarItemInfo)d)._OnThumbButtonsChanged(); + })); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/TaskbarItemProgressState.cs b/src/Shared/Microsoft.Windows.Shell/TaskbarItemProgressState.cs new file mode 100644 index 00000000..182986f3 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/TaskbarItemProgressState.cs @@ -0,0 +1,13 @@ +using System; + +namespace Microsoft.Windows.Shell +{ + public enum TaskbarItemProgressState + { + None, + Indeterminate, + Normal, + Error, + Paused + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/ThumbButtonInfo.cs b/src/Shared/Microsoft.Windows.Shell/ThumbButtonInfo.cs new file mode 100644 index 00000000..cc36e814 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/ThumbButtonInfo.cs @@ -0,0 +1,289 @@ +using System; +using System.ComponentModel; +using System.Windows; +using System.Windows.Input; +using System.Windows.Media; + +namespace Microsoft.Windows.Shell +{ + [DefaultEvent("Click")] + public sealed class ThumbButtonInfo : Freezable, ICommandSource + { + protected override Freezable CreateInstanceCore() + { + return new ThumbButtonInfo(); + } + + public Visibility Visibility + { + get + { + return (Visibility)base.GetValue(ThumbButtonInfo.VisibilityProperty); + } + set + { + base.SetValue(ThumbButtonInfo.VisibilityProperty, value); + } + } + + public bool DismissWhenClicked + { + get + { + return (bool)base.GetValue(ThumbButtonInfo.DismissWhenClickedProperty); + } + set + { + base.SetValue(ThumbButtonInfo.DismissWhenClickedProperty, value); + } + } + + public ImageSource ImageSource + { + get + { + return (ImageSource)base.GetValue(ThumbButtonInfo.ImageSourceProperty); + } + set + { + base.SetValue(ThumbButtonInfo.ImageSourceProperty, value); + } + } + + public bool IsBackgroundVisible + { + get + { + return (bool)base.GetValue(ThumbButtonInfo.IsBackgroundVisibleProperty); + } + set + { + base.SetValue(ThumbButtonInfo.IsBackgroundVisibleProperty, value); + } + } + + public string Description + { + get + { + return (string)base.GetValue(ThumbButtonInfo.DescriptionProperty); + } + set + { + base.SetValue(ThumbButtonInfo.DescriptionProperty, value); + } + } + + private static object _CoerceDescription(DependencyObject d, object value) + { + string text = (string)value; + if (text != null && text.Length >= 260) + { + text = text.Substring(0, 259); + } + return text; + } + + private object _CoerceIsEnabledValue(object value) + { + bool flag = (bool)value; + return flag && this._CanExecute; + } + + public bool IsEnabled + { + get + { + return (bool)base.GetValue(ThumbButtonInfo.IsEnabledProperty); + } + set + { + base.SetValue(ThumbButtonInfo.IsEnabledProperty, value); + } + } + + public bool IsInteractive + { + get + { + return (bool)base.GetValue(ThumbButtonInfo.IsInteractiveProperty); + } + set + { + base.SetValue(ThumbButtonInfo.IsInteractiveProperty, value); + } + } + + private void _OnCommandChanged(DependencyPropertyChangedEventArgs e) + { + ICommand command = (ICommand)e.OldValue; + ICommand command2 = (ICommand)e.NewValue; + if (command == command2) + { + return; + } + if (command != null) + { + this._UnhookCommand(command); + } + if (command2 != null) + { + this._HookCommand(command2); + } + } + + private bool _CanExecute + { + get + { + return (bool)base.GetValue(ThumbButtonInfo._CanExecuteProperty); + } + set + { + base.SetValue(ThumbButtonInfo._CanExecuteProperty, value); + } + } + + public event EventHandler Click; + + internal void InvokeClick() + { + EventHandler click = this.Click; + if (click != null) + { + click(this, EventArgs.Empty); + } + this._InvokeCommand(); + } + + private void _InvokeCommand() + { + ICommand command = this.Command; + if (command != null) + { + object commandParameter = this.CommandParameter; + IInputElement commandTarget = this.CommandTarget; + RoutedCommand routedCommand = command as RoutedCommand; + if (routedCommand != null) + { + if (routedCommand.CanExecute(commandParameter, commandTarget)) + { + routedCommand.Execute(commandParameter, commandTarget); + return; + } + } + else if (command.CanExecute(commandParameter)) + { + command.Execute(commandParameter); + } + } + } + + private void _UnhookCommand(ICommand command) + { + command.CanExecuteChanged -= this._commandEvent; + this._commandEvent = null; + this._UpdateCanExecute(); + } + + private void _HookCommand(ICommand command) + { + this._commandEvent = delegate(object sender, EventArgs e) + { + this._UpdateCanExecute(); + }; + command.CanExecuteChanged += this._commandEvent; + this._UpdateCanExecute(); + } + + private void _UpdateCanExecute() + { + if (this.Command == null) + { + this._CanExecute = true; + return; + } + object commandParameter = this.CommandParameter; + IInputElement commandTarget = this.CommandTarget; + RoutedCommand routedCommand = this.Command as RoutedCommand; + if (routedCommand != null) + { + this._CanExecute = routedCommand.CanExecute(commandParameter, commandTarget); + return; + } + this._CanExecute = this.Command.CanExecute(commandParameter); + } + + public ICommand Command + { + get + { + return (ICommand)base.GetValue(ThumbButtonInfo.CommandProperty); + } + set + { + base.SetValue(ThumbButtonInfo.CommandProperty, value); + } + } + + public object CommandParameter + { + get + { + return base.GetValue(ThumbButtonInfo.CommandParameterProperty); + } + set + { + base.SetValue(ThumbButtonInfo.CommandParameterProperty, value); + } + } + + public IInputElement CommandTarget + { + get + { + return (IInputElement)base.GetValue(ThumbButtonInfo.CommandTargetProperty); + } + set + { + base.SetValue(ThumbButtonInfo.CommandTargetProperty, value); + } + } + + private EventHandler _commandEvent; + + public static readonly DependencyProperty VisibilityProperty = DependencyProperty.Register("Visibility", typeof(Visibility), typeof(ThumbButtonInfo), new PropertyMetadata(Visibility.Visible)); + + public static readonly DependencyProperty DismissWhenClickedProperty = DependencyProperty.Register("DismissWhenClicked", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(false)); + + public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ThumbButtonInfo), new PropertyMetadata(null)); + + public static readonly DependencyProperty IsBackgroundVisibleProperty = DependencyProperty.Register("IsBackgroundVisible", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(true)); + + public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(ThumbButtonInfo), new PropertyMetadata(string.Empty, null, new CoerceValueCallback(ThumbButtonInfo._CoerceDescription))); + + public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.Register("IsEnabled", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(true, null, (DependencyObject d, object e) => ((ThumbButtonInfo)d)._CoerceIsEnabledValue(e))); + + public static readonly DependencyProperty IsInteractiveProperty = DependencyProperty.Register("IsInteractive", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(true)); + + public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(ThumbButtonInfo), new PropertyMetadata(null, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((ThumbButtonInfo)d)._OnCommandChanged(e); + })); + + public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(ThumbButtonInfo), new PropertyMetadata(null, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((ThumbButtonInfo)d)._UpdateCanExecute(); + })); + + public static readonly DependencyProperty CommandTargetProperty = DependencyProperty.Register("CommandTarget", typeof(IInputElement), typeof(ThumbButtonInfo), new PropertyMetadata(null, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((ThumbButtonInfo)d)._UpdateCanExecute(); + })); + + private static readonly DependencyProperty _CanExecuteProperty = DependencyProperty.Register("_CanExecute", typeof(bool), typeof(ThumbButtonInfo), new PropertyMetadata(true, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + d.CoerceValue(ThumbButtonInfo.IsEnabledProperty); + })); + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/ThumbButtonInfoCollection.cs b/src/Shared/Microsoft.Windows.Shell/ThumbButtonInfoCollection.cs new file mode 100644 index 00000000..5312c59f --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/ThumbButtonInfoCollection.cs @@ -0,0 +1,29 @@ +using System; +using System.Windows; + +namespace Microsoft.Windows.Shell +{ + public class ThumbButtonInfoCollection : FreezableCollection + { + protected override Freezable CreateInstanceCore() + { + return new ThumbButtonInfoCollection(); + } + + internal static ThumbButtonInfoCollection Empty + { + get + { + if (ThumbButtonInfoCollection.s_empty == null) + { + ThumbButtonInfoCollection thumbButtonInfoCollection = new ThumbButtonInfoCollection(); + thumbButtonInfoCollection.Freeze(); + ThumbButtonInfoCollection.s_empty = thumbButtonInfoCollection; + } + return ThumbButtonInfoCollection.s_empty; + } + } + + private static ThumbButtonInfoCollection s_empty; + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/WindowChrome.cs b/src/Shared/Microsoft.Windows.Shell/WindowChrome.cs new file mode 100644 index 00000000..f3a14f87 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/WindowChrome.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Windows; +using System.Windows.Data; +using Standard; + +namespace Microsoft.Windows.Shell +{ + public class WindowChrome : Freezable + { + public static Thickness GlassFrameCompleteThickness + { + get + { + return new Thickness(-1.0); + } + } + + private static void _OnChromeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (DesignerProperties.GetIsInDesignMode(d)) + { + return; + } + Window window = (Window)d; + WindowChrome windowChrome = (WindowChrome)e.NewValue; + WindowChromeWorker windowChromeWorker = WindowChromeWorker.GetWindowChromeWorker(window); + if (windowChromeWorker == null) + { + windowChromeWorker = new WindowChromeWorker(); + WindowChromeWorker.SetWindowChromeWorker(window, windowChromeWorker); + } + windowChromeWorker.SetWindowChrome(windowChrome); + } + + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] + public static WindowChrome GetWindowChrome(Window window) + { + Verify.IsNotNull(window, "window"); + return (WindowChrome)window.GetValue(WindowChrome.WindowChromeProperty); + } + + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] + public static void SetWindowChrome(Window window, WindowChrome chrome) + { + Verify.IsNotNull(window, "window"); + window.SetValue(WindowChrome.WindowChromeProperty, chrome); + } + + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] + public static bool GetIsHitTestVisibleInChrome(IInputElement inputElement) + { + Verify.IsNotNull(inputElement, "inputElement"); + DependencyObject dependencyObject = inputElement as DependencyObject; + if (dependencyObject == null) + { + throw new ArgumentException("The element must be a DependencyObject", "inputElement"); + } + return (bool)dependencyObject.GetValue(WindowChrome.IsHitTestVisibleInChromeProperty); + } + + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] + public static void SetIsHitTestVisibleInChrome(IInputElement inputElement, bool hitTestVisible) + { + Verify.IsNotNull(inputElement, "inputElement"); + DependencyObject dependencyObject = inputElement as DependencyObject; + if (dependencyObject == null) + { + throw new ArgumentException("The element must be a DependencyObject", "inputElement"); + } + dependencyObject.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, hitTestVisible); + } + + public double CaptionHeight + { + get + { + return (double)base.GetValue(WindowChrome.CaptionHeightProperty); + } + set + { + base.SetValue(WindowChrome.CaptionHeightProperty, value); + } + } + + public Thickness ResizeBorderThickness + { + get + { + return (Thickness)base.GetValue(WindowChrome.ResizeBorderThicknessProperty); + } + set + { + base.SetValue(WindowChrome.ResizeBorderThicknessProperty, value); + } + } + + private static object _CoerceGlassFrameThickness(Thickness thickness) + { + if (!Utility.IsThicknessNonNegative(thickness)) + { + return WindowChrome.GlassFrameCompleteThickness; + } + return thickness; + } + + public Thickness GlassFrameThickness + { + get + { + return (Thickness)base.GetValue(WindowChrome.GlassFrameThicknessProperty); + } + set + { + base.SetValue(WindowChrome.GlassFrameThicknessProperty, value); + } + } + + public CornerRadius CornerRadius + { + get + { + return (CornerRadius)base.GetValue(WindowChrome.CornerRadiusProperty); + } + set + { + base.SetValue(WindowChrome.CornerRadiusProperty, value); + } + } + + protected override Freezable CreateInstanceCore() + { + return new WindowChrome(); + } + + public WindowChrome() + { + foreach (WindowChrome._SystemParameterBoundProperty systemParameterBoundProperty in WindowChrome._BoundProperties) + { + BindingOperations.SetBinding(this, systemParameterBoundProperty.DependencyProperty, new Binding + { + Source = SystemParameters2.Current, + Path = new PropertyPath(systemParameterBoundProperty.SystemParameterPropertyName, new object[0]), + Mode = BindingMode.OneWay, + UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged + }); + } + } + + private void _OnPropertyChangedThatRequiresRepaint() + { + EventHandler propertyChangedThatRequiresRepaint = this.PropertyChangedThatRequiresRepaint; + if (propertyChangedThatRequiresRepaint != null) + { + propertyChangedThatRequiresRepaint(this, EventArgs.Empty); + } + } + + internal event EventHandler PropertyChangedThatRequiresRepaint; + + public static readonly DependencyProperty WindowChromeProperty = DependencyProperty.RegisterAttached("WindowChrome", typeof(WindowChrome), typeof(WindowChrome), new PropertyMetadata(null, new PropertyChangedCallback(WindowChrome._OnChromeChanged))); + + public static readonly DependencyProperty IsHitTestVisibleInChromeProperty = DependencyProperty.RegisterAttached("IsHitTestVisibleInChrome", typeof(bool), typeof(WindowChrome), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits)); + + public static readonly DependencyProperty CaptionHeightProperty = DependencyProperty.Register("CaptionHeight", typeof(double), typeof(WindowChrome), new PropertyMetadata(0.0, delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((WindowChrome)d)._OnPropertyChangedThatRequiresRepaint(); + }), (object value) => (double)value >= 0.0); + + public static readonly DependencyProperty ResizeBorderThicknessProperty = DependencyProperty.Register("ResizeBorderThickness", typeof(Thickness), typeof(WindowChrome), new PropertyMetadata(default(Thickness)), (object value) => Utility.IsThicknessNonNegative((Thickness)value)); + + public static readonly DependencyProperty GlassFrameThicknessProperty = DependencyProperty.Register("GlassFrameThickness", typeof(Thickness), typeof(WindowChrome), new PropertyMetadata(default(Thickness), delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((WindowChrome)d)._OnPropertyChangedThatRequiresRepaint(); + }, (DependencyObject d, object o) => WindowChrome._CoerceGlassFrameThickness((Thickness)o))); + + public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(WindowChrome), new PropertyMetadata(default(CornerRadius), delegate(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((WindowChrome)d)._OnPropertyChangedThatRequiresRepaint(); + }), (object value) => Utility.IsCornerRadiusValid((CornerRadius)value)); + + private static readonly List _BoundProperties = new List + { + new WindowChrome._SystemParameterBoundProperty + { + DependencyProperty = WindowChrome.CornerRadiusProperty, + SystemParameterPropertyName = "WindowCornerRadius" + }, + new WindowChrome._SystemParameterBoundProperty + { + DependencyProperty = WindowChrome.CaptionHeightProperty, + SystemParameterPropertyName = "WindowCaptionHeight" + }, + new WindowChrome._SystemParameterBoundProperty + { + DependencyProperty = WindowChrome.ResizeBorderThicknessProperty, + SystemParameterPropertyName = "WindowResizeBorderThickness" + }, + new WindowChrome._SystemParameterBoundProperty + { + DependencyProperty = WindowChrome.GlassFrameThicknessProperty, + SystemParameterPropertyName = "WindowNonClientFrameThickness" + } + }; + + private struct _SystemParameterBoundProperty + { + public string SystemParameterPropertyName { get; set; } + + public DependencyProperty DependencyProperty { get; set; } + } + } +} diff --git a/src/Shared/Microsoft.Windows.Shell/WindowChromeWorker.cs b/src/Shared/Microsoft.Windows.Shell/WindowChromeWorker.cs new file mode 100644 index 00000000..ed3d2bd2 --- /dev/null +++ b/src/Shared/Microsoft.Windows.Shell/WindowChromeWorker.cs @@ -0,0 +1,816 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Interop; +using System.Windows.Media; +using System.Windows.Threading; +using Standard; + +namespace Microsoft.Windows.Shell +{ + internal class WindowChromeWorker : DependencyObject + { + public WindowChromeWorker() + { + this._messageTable = new List> + { + new KeyValuePair(WM.SETTEXT, new MessageHandler(this._HandleSetTextOrIcon)), + new KeyValuePair(WM.SETICON, new MessageHandler(this._HandleSetTextOrIcon)), + new KeyValuePair(WM.NCACTIVATE, new MessageHandler(this._HandleNCActivate)), + new KeyValuePair(WM.NCCALCSIZE, new MessageHandler(this._HandleNCCalcSize)), + new KeyValuePair(WM.NCHITTEST, new MessageHandler(this._HandleNCHitTest)), + new KeyValuePair(WM.NCRBUTTONUP, new MessageHandler(this._HandleNCRButtonUp)), + new KeyValuePair(WM.SIZE, new MessageHandler(this._HandleSize)), + new KeyValuePair(WM.WINDOWPOSCHANGED, new MessageHandler(this._HandleWindowPosChanged)), + new KeyValuePair(WM.DWMCOMPOSITIONCHANGED, new MessageHandler(this._HandleDwmCompositionChanged)) + }; + if (Utility.IsPresentationFrameworkVersionLessThan4) + { + this._messageTable.AddRange(new KeyValuePair[] + { + new KeyValuePair(WM.WININICHANGE, new MessageHandler(this._HandleSettingChange)), + new KeyValuePair(WM.ENTERSIZEMOVE, new MessageHandler(this._HandleEnterSizeMove)), + new KeyValuePair(WM.EXITSIZEMOVE, new MessageHandler(this._HandleExitSizeMove)), + new KeyValuePair(WM.MOVE, new MessageHandler(this._HandleMove)) + }); + } + } + + public void SetWindowChrome(WindowChrome newChrome) + { + base.VerifyAccess(); + if (newChrome == this._chromeInfo) + { + return; + } + if (this._chromeInfo != null) + { + this._chromeInfo.PropertyChangedThatRequiresRepaint -= this._OnChromePropertyChangedThatRequiresRepaint; + } + this._chromeInfo = newChrome; + if (this._chromeInfo != null) + { + this._chromeInfo.PropertyChangedThatRequiresRepaint += this._OnChromePropertyChangedThatRequiresRepaint; + } + this._ApplyNewCustomChrome(); + } + + private void _OnChromePropertyChangedThatRequiresRepaint(object sender, EventArgs e) + { + this._UpdateFrameState(true); + } + + private static void _OnChromeWorkerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + Window window = (Window)d; + WindowChromeWorker windowChromeWorker = (WindowChromeWorker)e.NewValue; + windowChromeWorker._SetWindow(window); + } + + private void _SetWindow(Window window) + { + this._window = window; + this._hwnd = new WindowInteropHelper(this._window).Handle; + if (Utility.IsPresentationFrameworkVersionLessThan4) + { + Utility.AddDependencyPropertyChangeListener(this._window, Control.TemplateProperty, new EventHandler(this._OnWindowPropertyChangedThatRequiresTemplateFixup)); + Utility.AddDependencyPropertyChangeListener(this._window, FrameworkElement.FlowDirectionProperty, new EventHandler(this._OnWindowPropertyChangedThatRequiresTemplateFixup)); + } + this._window.Closed += this._UnsetWindow; + if (IntPtr.Zero != this._hwnd) + { + this._hwndSource = HwndSource.FromHwnd(this._hwnd); + this._window.ApplyTemplate(); + if (this._chromeInfo != null) + { + this._ApplyNewCustomChrome(); + return; + } + } + else + { + this._window.SourceInitialized += delegate(object sender, EventArgs e) + { + this._hwnd = new WindowInteropHelper(this._window).Handle; + this._hwndSource = HwndSource.FromHwnd(this._hwnd); + if (this._chromeInfo != null) + { + this._ApplyNewCustomChrome(); + } + }; + } + } + + private void _UnsetWindow(object sender, EventArgs e) + { + if (Utility.IsPresentationFrameworkVersionLessThan4) + { + Utility.RemoveDependencyPropertyChangeListener(this._window, Control.TemplateProperty, new EventHandler(this._OnWindowPropertyChangedThatRequiresTemplateFixup)); + Utility.RemoveDependencyPropertyChangeListener(this._window, FrameworkElement.FlowDirectionProperty, new EventHandler(this._OnWindowPropertyChangedThatRequiresTemplateFixup)); + } + if (this._chromeInfo != null) + { + this._chromeInfo.PropertyChangedThatRequiresRepaint -= this._OnChromePropertyChangedThatRequiresRepaint; + } + this._RestoreStandardChromeState(true); + } + + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + public static WindowChromeWorker GetWindowChromeWorker(Window window) + { + Verify.IsNotNull(window, "window"); + return (WindowChromeWorker)window.GetValue(WindowChromeWorker.WindowChromeWorkerProperty); + } + + [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + public static void SetWindowChromeWorker(Window window, WindowChromeWorker chrome) + { + Verify.IsNotNull(window, "window"); + window.SetValue(WindowChromeWorker.WindowChromeWorkerProperty, chrome); + } + + private void _OnWindowPropertyChangedThatRequiresTemplateFixup(object sender, EventArgs e) + { + if (this._chromeInfo != null && this._hwnd != IntPtr.Zero) + { + this._window.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new WindowChromeWorker._Action(this._FixupFrameworkIssues)); + } + } + + private void _ApplyNewCustomChrome() + { + if (this._hwnd == IntPtr.Zero) + { + return; + } + if (this._chromeInfo == null) + { + this._RestoreStandardChromeState(false); + return; + } + if (!this._isHooked) + { + this._hwndSource.AddHook(new HwndSourceHook(this._WndProc)); + this._isHooked = true; + } + this._FixupFrameworkIssues(); + this._UpdateSystemMenu(new WindowState?(this._window.WindowState)); + this._UpdateFrameState(true); + NativeMethods.SetWindowPos(this._hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP.DRAWFRAME | SWP.NOACTIVATE | SWP.NOMOVE | SWP.NOOWNERZORDER | SWP.NOSIZE | SWP.NOZORDER); + } + + private void _FixupFrameworkIssues() + { + if (!Utility.IsPresentationFrameworkVersionLessThan4) + { + return; + } + if (this._window.Template == null) + { + return; + } + if (VisualTreeHelper.GetChildrenCount(this._window) == 0) + { + this._window.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new WindowChromeWorker._Action(this._FixupFrameworkIssues)); + return; + } + FrameworkElement frameworkElement = (FrameworkElement)VisualTreeHelper.GetChild(this._window, 0); + RECT windowRect = NativeMethods.GetWindowRect(this._hwnd); + RECT rect = this._GetAdjustedWindowRect(windowRect); + Rect rect2 = DpiHelper.DeviceRectToLogical(new Rect((double)windowRect.Left, (double)windowRect.Top, (double)windowRect.Width, (double)windowRect.Height)); + Rect rect3 = DpiHelper.DeviceRectToLogical(new Rect((double)rect.Left, (double)rect.Top, (double)rect.Width, (double)rect.Height)); + Thickness thickness = new Thickness(rect2.Left - rect3.Left, rect2.Top - rect3.Top, rect3.Right - rect2.Right, rect3.Bottom - rect2.Bottom); + frameworkElement.Margin = new Thickness(0.0, 0.0, -(thickness.Left + thickness.Right), -(thickness.Top + thickness.Bottom)); + if (this._window.FlowDirection == FlowDirection.RightToLeft) + { + frameworkElement.RenderTransform = new MatrixTransform(1.0, 0.0, 0.0, 1.0, -(thickness.Left + thickness.Right), 0.0); + } + else + { + frameworkElement.RenderTransform = null; + } + if (!this._isFixedUp) + { + this._hasUserMovedWindow = false; + this._window.StateChanged += this._FixupRestoreBounds; + this._isFixedUp = true; + } + } + + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] + private void _FixupWindows7Issues() + { + if (this._blackGlassFixupAttemptCount > 5) + { + return; + } + if (Utility.IsOSWindows7OrNewer && NativeMethods.DwmIsCompositionEnabled()) + { + this._blackGlassFixupAttemptCount++; + bool flag = false; + try + { + flag = (NativeMethods.DwmGetCompositionTimingInfo(this._hwnd) != null); + } + catch (Exception) + { + } + if (!flag) + { + base.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new WindowChromeWorker._Action(this._FixupWindows7Issues)); + return; + } + this._blackGlassFixupAttemptCount = 0; + } + } + + private void _FixupRestoreBounds(object sender, EventArgs e) + { + if ((this._window.WindowState == WindowState.Maximized || this._window.WindowState == WindowState.Minimized) && this._hasUserMovedWindow) + { + this._hasUserMovedWindow = false; + WINDOWPLACEMENT windowPlacement = NativeMethods.GetWindowPlacement(this._hwnd); + RECT rect = this._GetAdjustedWindowRect(new RECT + { + Bottom = 100, + Right = 100 + }); + Point point = DpiHelper.DevicePixelsToLogical(new Point((double)(windowPlacement.rcNormalPosition.Left - rect.Left), (double)(windowPlacement.rcNormalPosition.Top - rect.Top))); + this._window.Top = point.Y; + this._window.Left = point.X; + } + } + + private RECT _GetAdjustedWindowRect(RECT rcWindow) + { + WS dwStyle = (WS)((int)NativeMethods.GetWindowLongPtr(this._hwnd, GWL.STYLE)); + WS_EX dwExStyle = (WS_EX)((int)NativeMethods.GetWindowLongPtr(this._hwnd, GWL.EXSTYLE)); + return NativeMethods.AdjustWindowRectEx(rcWindow, dwStyle, false, dwExStyle); + } + + private bool _IsWindowDocked + { + get + { + if (this._window.WindowState != WindowState.Normal) + { + return false; + } + RECT rect = this._GetAdjustedWindowRect(new RECT + { + Bottom = 100, + Right = 100 + }); + Point point = new Point(this._window.Left, this._window.Top); + point -= (Vector)DpiHelper.DevicePixelsToLogical(new Point((double)rect.Left, (double)rect.Top)); + return this._window.RestoreBounds.Location != point; + } + } + + private IntPtr _WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + foreach (KeyValuePair keyValuePair in this._messageTable) + { + if (keyValuePair.Key == (WM)msg) + { + return keyValuePair.Value((WM)msg, wParam, lParam, out handled); + } + } + return IntPtr.Zero; + } + + private IntPtr _HandleSetTextOrIcon(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + bool flag = this._ModifyStyle(WS.VISIBLE, WS.OVERLAPPED); + IntPtr result = NativeMethods.DefWindowProc(this._hwnd, uMsg, wParam, lParam); + if (flag) + { + this._ModifyStyle(WS.OVERLAPPED, WS.VISIBLE); + } + handled = true; + return result; + } + + private IntPtr _HandleNCActivate(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + IntPtr result = NativeMethods.DefWindowProc(this._hwnd, WM.NCACTIVATE, wParam, new IntPtr(-1)); + handled = true; + return result; + } + + private IntPtr _HandleNCCalcSize(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + handled = true; + return new IntPtr(768); + } + + private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + IntPtr intPtr = IntPtr.Zero; + handled = false; + if (Utility.IsOSVistaOrNewer && this._chromeInfo.GlassFrameThickness != default(Thickness) && this._isGlassEnabled) + { + handled = NativeMethods.DwmDefWindowProc(this._hwnd, uMsg, wParam, lParam, out intPtr); + } + if (IntPtr.Zero == intPtr) + { + Point point = new Point((double)Utility.GET_X_LPARAM(lParam), (double)Utility.GET_Y_LPARAM(lParam)); + Rect deviceRectangle = this._GetWindowRect(); + HT ht = this._HitTestNca(DpiHelper.DeviceRectToLogical(deviceRectangle), DpiHelper.DevicePixelsToLogical(point)); + if (ht != HT.CLIENT) + { + Point point2 = point; + point2.Offset(-deviceRectangle.X, -deviceRectangle.Y); + point2 = DpiHelper.DevicePixelsToLogical(point2); + IInputElement inputElement = this._window.InputHitTest(point2); + if (inputElement != null && WindowChrome.GetIsHitTestVisibleInChrome(inputElement)) + { + ht = HT.CLIENT; + } + } + handled = true; + intPtr = new IntPtr((int)ht); + } + return intPtr; + } + + private IntPtr _HandleNCRButtonUp(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + if (2 == wParam.ToInt32()) + { + SystemCommands.ShowSystemMenuPhysicalCoordinates(this._window, new Point((double)Utility.GET_X_LPARAM(lParam), (double)Utility.GET_Y_LPARAM(lParam))); + } + handled = false; + return IntPtr.Zero; + } + + private IntPtr _HandleSize(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + WindowState? assumeState = null; + if (wParam.ToInt32() == 2) + { + assumeState = new WindowState?(WindowState.Maximized); + } + this._UpdateSystemMenu(assumeState); + handled = false; + return IntPtr.Zero; + } + + private IntPtr _HandleWindowPosChanged(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + this._UpdateSystemMenu(null); + if (!this._isGlassEnabled) + { + WINDOWPOS value = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS)); + this._SetRoundingRegion(new WINDOWPOS?(value)); + } + handled = false; + return IntPtr.Zero; + } + + private IntPtr _HandleDwmCompositionChanged(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + this._UpdateFrameState(false); + handled = false; + return IntPtr.Zero; + } + + private IntPtr _HandleSettingChange(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + this._FixupFrameworkIssues(); + handled = false; + return IntPtr.Zero; + } + + private IntPtr _HandleEnterSizeMove(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + this._isUserResizing = true; + if (this._window.WindowState != WindowState.Maximized && !this._IsWindowDocked) + { + this._windowPosAtStartOfUserMove = new Point(this._window.Left, this._window.Top); + } + handled = false; + return IntPtr.Zero; + } + + private IntPtr _HandleExitSizeMove(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + this._isUserResizing = false; + if (this._window.WindowState == WindowState.Maximized) + { + this._window.Top = this._windowPosAtStartOfUserMove.Y; + this._window.Left = this._windowPosAtStartOfUserMove.X; + } + handled = false; + return IntPtr.Zero; + } + + private IntPtr _HandleMove(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled) + { + if (this._isUserResizing) + { + this._hasUserMovedWindow = true; + } + handled = false; + return IntPtr.Zero; + } + + private bool _ModifyStyle(WS removeStyle, WS addStyle) + { + WS ws = (WS)NativeMethods.GetWindowLongPtr(this._hwnd, GWL.STYLE).ToInt32(); + WS ws2 = (ws & ~removeStyle) | addStyle; + if (ws == ws2) + { + return false; + } + NativeMethods.SetWindowLongPtr(this._hwnd, GWL.STYLE, new IntPtr((int)ws2)); + return true; + } + + private WindowState _GetHwndState() + { + WINDOWPLACEMENT windowPlacement = NativeMethods.GetWindowPlacement(this._hwnd); + switch (windowPlacement.showCmd) + { + case SW.SHOWMINIMIZED: + return WindowState.Minimized; + case SW.SHOWMAXIMIZED: + return WindowState.Maximized; + default: + return WindowState.Normal; + } + } + + private Rect _GetWindowRect() + { + RECT windowRect = NativeMethods.GetWindowRect(this._hwnd); + return new Rect((double)windowRect.Left, (double)windowRect.Top, (double)windowRect.Width, (double)windowRect.Height); + } + + private void _UpdateSystemMenu(WindowState? assumeState) + { + WindowState windowState = assumeState ?? this._GetHwndState(); + if (assumeState != null || this._lastMenuState != windowState) + { + this._lastMenuState = windowState; + bool flag = this._ModifyStyle(WS.VISIBLE, WS.OVERLAPPED); + IntPtr systemMenu = NativeMethods.GetSystemMenu(this._hwnd, false); + if (IntPtr.Zero != systemMenu) + { + WS value = (WS)NativeMethods.GetWindowLongPtr(this._hwnd, GWL.STYLE).ToInt32(); + bool flag2 = Utility.IsFlagSet((int)value, 131072); + bool flag3 = Utility.IsFlagSet((int)value, 65536); + bool flag4 = Utility.IsFlagSet((int)value, 262144); + switch (windowState) + { + case WindowState.Minimized: + NativeMethods.EnableMenuItem(systemMenu, SC.RESTORE, MF.ENABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.MOVE, MF.GRAYED | MF.DISABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.SIZE, MF.GRAYED | MF.DISABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.MINIMIZE, MF.GRAYED | MF.DISABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.MAXIMIZE, flag3 ? MF.ENABLED : (MF.GRAYED | MF.DISABLED)); + break; + case WindowState.Maximized: + NativeMethods.EnableMenuItem(systemMenu, SC.RESTORE, MF.ENABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.MOVE, MF.GRAYED | MF.DISABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.SIZE, MF.GRAYED | MF.DISABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.MINIMIZE, flag2 ? MF.ENABLED : (MF.GRAYED | MF.DISABLED)); + NativeMethods.EnableMenuItem(systemMenu, SC.MAXIMIZE, MF.GRAYED | MF.DISABLED); + break; + default: + NativeMethods.EnableMenuItem(systemMenu, SC.RESTORE, MF.GRAYED | MF.DISABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.MOVE, MF.ENABLED); + NativeMethods.EnableMenuItem(systemMenu, SC.SIZE, flag4 ? MF.ENABLED : (MF.GRAYED | MF.DISABLED)); + NativeMethods.EnableMenuItem(systemMenu, SC.MINIMIZE, flag2 ? MF.ENABLED : (MF.GRAYED | MF.DISABLED)); + NativeMethods.EnableMenuItem(systemMenu, SC.MAXIMIZE, flag3 ? MF.ENABLED : (MF.GRAYED | MF.DISABLED)); + break; + } + } + if (flag) + { + this._ModifyStyle(WS.OVERLAPPED, WS.VISIBLE); + } + } + } + + private void _UpdateFrameState(bool force) + { + if (IntPtr.Zero == this._hwnd) + { + return; + } + bool flag = NativeMethods.DwmIsCompositionEnabled(); + if (force || flag != this._isGlassEnabled) + { + this._isGlassEnabled = (flag && this._chromeInfo.GlassFrameThickness != default(Thickness)); + if (!this._isGlassEnabled) + { + this._SetRoundingRegion(null); + } + else + { + this._ClearRoundingRegion(); + this._ExtendGlassFrame(); + this._FixupWindows7Issues(); + } + NativeMethods.SetWindowPos(this._hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP.DRAWFRAME | SWP.NOACTIVATE | SWP.NOMOVE | SWP.NOOWNERZORDER | SWP.NOSIZE | SWP.NOZORDER); + } + } + + private void _ClearRoundingRegion() + { + NativeMethods.SetWindowRgn(this._hwnd, IntPtr.Zero, NativeMethods.IsWindowVisible(this._hwnd)); + } + + private void _SetRoundingRegion(WINDOWPOS? wp) + { + WINDOWPLACEMENT windowPlacement = NativeMethods.GetWindowPlacement(this._hwnd); + if (windowPlacement.showCmd == SW.SHOWMAXIMIZED) + { + int num; + int num2; + if (wp != null) + { + num = wp.Value.x; + num2 = wp.Value.y; + } + else + { + Rect rect = this._GetWindowRect(); + num = (int)rect.Left; + num2 = (int)rect.Top; + } + IntPtr hMonitor = NativeMethods.MonitorFromWindow(this._hwnd, 2u); + MONITORINFO monitorInfo = NativeMethods.GetMonitorInfo(hMonitor); + RECT rcWork = monitorInfo.rcWork; + rcWork.Offset(-num, -num2); + IntPtr hRgn = IntPtr.Zero; + try + { + hRgn = NativeMethods.CreateRectRgnIndirect(rcWork); + NativeMethods.SetWindowRgn(this._hwnd, hRgn, NativeMethods.IsWindowVisible(this._hwnd)); + hRgn = IntPtr.Zero; + return; + } + finally + { + Utility.SafeDeleteObject(ref hRgn); + } + } + Size size; + if (wp != null && !Utility.IsFlagSet(wp.Value.flags, 1)) + { + size = new Size((double)wp.Value.cx, (double)wp.Value.cy); + } + else + { + if (wp != null && this._lastRoundingState == this._window.WindowState) + { + return; + } + size = this._GetWindowRect().Size; + } + this._lastRoundingState = this._window.WindowState; + IntPtr intPtr = IntPtr.Zero; + try + { + double num3 = Math.Min(size.Width, size.Height); + double num4 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopLeft, 0.0)).X; + num4 = Math.Min(num4, num3 / 2.0); + if (WindowChromeWorker._IsUniform(this._chromeInfo.CornerRadius)) + { + intPtr = WindowChromeWorker._CreateRoundRectRgn(new Rect(size), num4); + } + else + { + intPtr = WindowChromeWorker._CreateRoundRectRgn(new Rect(0.0, 0.0, size.Width / 2.0 + num4, size.Height / 2.0 + num4), num4); + double num5 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.TopRight, 0.0)).X; + num5 = Math.Min(num5, num3 / 2.0); + Rect region = new Rect(0.0, 0.0, size.Width / 2.0 + num5, size.Height / 2.0 + num5); + region.Offset(size.Width / 2.0 - num5, 0.0); + WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region, num5); + double num6 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.BottomLeft, 0.0)).X; + num6 = Math.Min(num6, num3 / 2.0); + Rect region2 = new Rect(0.0, 0.0, size.Width / 2.0 + num6, size.Height / 2.0 + num6); + region2.Offset(0.0, size.Height / 2.0 - num6); + WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region2, num6); + double num7 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.CornerRadius.BottomRight, 0.0)).X; + num7 = Math.Min(num7, num3 / 2.0); + Rect region3 = new Rect(0.0, 0.0, size.Width / 2.0 + num7, size.Height / 2.0 + num7); + region3.Offset(size.Width / 2.0 - num7, size.Height / 2.0 - num7); + WindowChromeWorker._CreateAndCombineRoundRectRgn(intPtr, region3, num7); + } + NativeMethods.SetWindowRgn(this._hwnd, intPtr, NativeMethods.IsWindowVisible(this._hwnd)); + intPtr = IntPtr.Zero; + } + finally + { + Utility.SafeDeleteObject(ref intPtr); + } + } + + private static IntPtr _CreateRoundRectRgn(Rect region, double radius) + { + if (DoubleUtilities.AreClose(0.0, radius)) + { + return NativeMethods.CreateRectRgn((int)Math.Floor(region.Left), (int)Math.Floor(region.Top), (int)Math.Ceiling(region.Right), (int)Math.Ceiling(region.Bottom)); + } + return NativeMethods.CreateRoundRectRgn((int)Math.Floor(region.Left), (int)Math.Floor(region.Top), (int)Math.Ceiling(region.Right) + 1, (int)Math.Ceiling(region.Bottom) + 1, (int)Math.Ceiling(radius), (int)Math.Ceiling(radius)); + } + + [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "HRGNs")] + private static void _CreateAndCombineRoundRectRgn(IntPtr hrgnSource, Rect region, double radius) + { + IntPtr hrgnSrc = IntPtr.Zero; + try + { + hrgnSrc = WindowChromeWorker._CreateRoundRectRgn(region, radius); + if (NativeMethods.CombineRgn(hrgnSource, hrgnSource, hrgnSrc, RGN.OR) == CombineRgnResult.ERROR) + { + throw new InvalidOperationException("Unable to combine two HRGNs."); + } + } + catch + { + Utility.SafeDeleteObject(ref hrgnSrc); + throw; + } + } + + private static bool _IsUniform(CornerRadius cornerRadius) + { + return DoubleUtilities.AreClose(cornerRadius.BottomLeft, cornerRadius.BottomRight) && DoubleUtilities.AreClose(cornerRadius.TopLeft, cornerRadius.TopRight) && DoubleUtilities.AreClose(cornerRadius.BottomLeft, cornerRadius.TopRight); + } + + private void _ExtendGlassFrame() + { + if (!Utility.IsOSVistaOrNewer) + { + return; + } + if (IntPtr.Zero == this._hwnd) + { + return; + } + if (!NativeMethods.DwmIsCompositionEnabled()) + { + this._hwndSource.CompositionTarget.BackgroundColor = SystemColors.WindowColor; + return; + } + this._hwndSource.CompositionTarget.BackgroundColor = Colors.Transparent; + Point point = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.GlassFrameThickness.Left, this._chromeInfo.GlassFrameThickness.Top)); + Point point2 = DpiHelper.LogicalPixelsToDevice(new Point(this._chromeInfo.GlassFrameThickness.Right, this._chromeInfo.GlassFrameThickness.Bottom)); + MARGINS margins = new MARGINS + { + cxLeftWidth = (int)Math.Ceiling(point.X), + cxRightWidth = (int)Math.Ceiling(point2.X), + cyTopHeight = (int)Math.Ceiling(point.Y), + cyBottomHeight = (int)Math.Ceiling(point2.Y) + }; + NativeMethods.DwmExtendFrameIntoClientArea(this._hwnd, ref margins); + } + + private HT _HitTestNca(Rect windowPosition, Point mousePosition) + { + int num = 1; + int num2 = 1; + bool flag = false; + if (mousePosition.Y >= windowPosition.Top && mousePosition.Y < windowPosition.Top + this._chromeInfo.ResizeBorderThickness.Top + this._chromeInfo.CaptionHeight) + { + flag = (mousePosition.Y < windowPosition.Top + this._chromeInfo.ResizeBorderThickness.Top); + num = 0; + } + else if (mousePosition.Y < windowPosition.Bottom && mousePosition.Y >= windowPosition.Bottom - (double)((int)this._chromeInfo.ResizeBorderThickness.Bottom)) + { + num = 2; + } + if (mousePosition.X >= windowPosition.Left && mousePosition.X < windowPosition.Left + (double)((int)this._chromeInfo.ResizeBorderThickness.Left)) + { + num2 = 0; + } + else if (mousePosition.X < windowPosition.Right && mousePosition.X >= windowPosition.Right - this._chromeInfo.ResizeBorderThickness.Right) + { + num2 = 2; + } + if (num == 0 && num2 != 1 && !flag) + { + num = 1; + } + HT ht = WindowChromeWorker._HitTestBorders[num, num2]; + if (ht == HT.TOP && !flag) + { + ht = HT.CAPTION; + } + return ht; + } + + private void _RestoreStandardChromeState(bool isClosing) + { + base.VerifyAccess(); + this._UnhookCustomChrome(); + if (!isClosing) + { + this._RestoreFrameworkIssueFixups(); + this._RestoreGlassFrame(); + this._RestoreHrgn(); + this._window.InvalidateMeasure(); + } + } + + private void _UnhookCustomChrome() + { + if (this._isHooked) + { + this._hwndSource.RemoveHook(new HwndSourceHook(this._WndProc)); + this._isHooked = false; + } + } + + private void _RestoreFrameworkIssueFixups() + { + if (Utility.IsPresentationFrameworkVersionLessThan4) + { + FrameworkElement frameworkElement = (FrameworkElement)VisualTreeHelper.GetChild(this._window, 0); + frameworkElement.Margin = default(Thickness); + this._window.StateChanged -= this._FixupRestoreBounds; + this._isFixedUp = false; + } + } + + private void _RestoreGlassFrame() + { + if (!Utility.IsOSVistaOrNewer || this._hwnd == IntPtr.Zero) + { + return; + } + this._hwndSource.CompositionTarget.BackgroundColor = SystemColors.WindowColor; + if (NativeMethods.DwmIsCompositionEnabled()) + { + MARGINS margins = default(MARGINS); + NativeMethods.DwmExtendFrameIntoClientArea(this._hwnd, ref margins); + } + } + + private void _RestoreHrgn() + { + this._ClearRoundingRegion(); + NativeMethods.SetWindowPos(this._hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP.DRAWFRAME | SWP.NOACTIVATE | SWP.NOMOVE | SWP.NOOWNERZORDER | SWP.NOSIZE | SWP.NOZORDER); + } + + // Note: this type is marked as 'beforefieldinit'. + static WindowChromeWorker() + { + HT[,] array = new HT[3, 3]; + array[0, 0] = HT.TOPLEFT; + array[0, 1] = HT.TOP; + array[0, 2] = HT.TOPRIGHT; + array[1, 0] = HT.LEFT; + array[1, 1] = HT.CLIENT; + array[1, 2] = HT.RIGHT; + array[2, 0] = HT.BOTTOMLEFT; + array[2, 1] = HT.BOTTOM; + array[2, 2] = HT.BOTTOMRIGHT; + WindowChromeWorker._HitTestBorders = array; + } + + private const SWP _SwpFlags = SWP.DRAWFRAME | SWP.NOACTIVATE | SWP.NOMOVE | SWP.NOOWNERZORDER | SWP.NOSIZE | SWP.NOZORDER; + + private readonly List> _messageTable; + + private Window _window; + + private IntPtr _hwnd; + + private HwndSource _hwndSource; + + private bool _isHooked; + + private bool _isFixedUp; + + private bool _isUserResizing; + + private bool _hasUserMovedWindow; + + private Point _windowPosAtStartOfUserMove = default(Point); + + private int _blackGlassFixupAttemptCount; + + private WindowChrome _chromeInfo; + + private WindowState _lastRoundingState; + + private WindowState _lastMenuState; + + private bool _isGlassEnabled; + + public static readonly DependencyProperty WindowChromeWorkerProperty = DependencyProperty.RegisterAttached("WindowChromeWorker", typeof(WindowChromeWorker), typeof(WindowChromeWorker), new PropertyMetadata(null, new PropertyChangedCallback(WindowChromeWorker._OnChromeWorkerChanged))); + + [SuppressMessage("Microsoft.Performance", "CA1814:PreferJaggedArraysOverMultidimensional", MessageId = "Member")] + private static readonly HT[,] _HitTestBorders; + + private delegate void _Action(); + } +}