diff --git a/Business/Menus.cs b/Business/Menus.cs
index 9bab3e8..ff5b506 100644
--- a/Business/Menus.cs
+++ b/Business/Menus.cs
@@ -443,7 +443,7 @@ namespace SystemTrayMenu.Business
rowData.ContainsMenu = true;
rowData.HiddenEntry = hiddenEntry;
string resolvedLnkPath = string.Empty;
- rowData.ReadIcon(true, ref resolvedLnkPath);
+ rowData.ReadIcon(true, ref resolvedLnkPath, level);
rowData.MenuLevel = level;
menuData.RowDatas.Add(rowData);
}
@@ -495,7 +495,7 @@ namespace SystemTrayMenu.Business
RowData rowData = ReadRowData(file, false);
string resolvedLnkPath = string.Empty;
- if (rowData.ReadIcon(false, ref resolvedLnkPath))
+ if (rowData.ReadIcon(false, ref resolvedLnkPath, level))
{
rowData = ReadRowData(resolvedLnkPath, true, rowData);
rowData.ContainsMenu = true;
@@ -918,7 +918,11 @@ namespace SystemTrayMenu.Business
if (IconReader.ClearIfCacheTooBig())
{
GC.Collect();
- MainPreload();
+
+ if (!Properties.Settings.Default.CacheMainMenu)
+ {
+ MainPreload();
+ }
}
openCloseState = OpenCloseState.Default;
diff --git a/DataClasses/RowData.cs b/DataClasses/RowData.cs
index f6fdace..a9a7a65 100644
--- a/DataClasses/RowData.cs
+++ b/DataClasses/RowData.cs
@@ -86,7 +86,7 @@ namespace SystemTrayMenu.DataClasses
row[2] = data;
}
- internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
+ internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath, int level)
{
bool isLnkDirectory = false;
@@ -96,7 +96,7 @@ namespace SystemTrayMenu.DataClasses
}
else if (isDirectory)
{
- icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Closed, false, true, MenuLevel == 0, out bool loading);
+ icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Closed, false, true, level == 0, out bool loading);
IconLoading = loading;
}
else
@@ -107,19 +107,17 @@ namespace SystemTrayMenu.DataClasses
if (fileExtension == ".lnk")
{
- handled = SetLnk(
- ref isLnkDirectory,
- ref resolvedLnkPath);
+ handled = SetLnk(level, ref isLnkDirectory, ref resolvedLnkPath);
showOverlay = true;
}
else if (fileExtension == ".url")
{
- handled = SetUrl();
+ handled = SetUrl(level);
showOverlay = true;
}
else if (fileExtension == ".sln")
{
- handled = SetSln();
+ handled = SetSln(level);
}
else if (fileExtension == ".appref-ms")
{
@@ -131,7 +129,7 @@ namespace SystemTrayMenu.DataClasses
try
{
FilePathIcon = TargetFilePathOrig;
- icon = IconReader.GetFileIconWithCache(FilePathIcon, showOverlay, true, MenuLevel == 0, out bool loading);
+ icon = IconReader.GetFileIconWithCache(FilePathIcon, showOverlay, true, level == 0, out bool loading);
IconLoading = loading;
}
catch (Exception ex)
@@ -256,7 +254,7 @@ namespace SystemTrayMenu.DataClasses
}
}
- private bool SetLnk(ref bool isLnkDirectory, ref string resolvedLnkPath)
+ private bool SetLnk(int level, ref bool isLnkDirectory, ref string resolvedLnkPath)
{
bool handled = false;
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
@@ -267,7 +265,7 @@ namespace SystemTrayMenu.DataClasses
}
else if (string.IsNullOrEmpty(Path.GetExtension(resolvedLnkPath)))
{
- icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Open, true, true, MenuLevel == 0, out bool loading);
+ icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Open, true, true, level == 0, out bool loading);
IconLoading = loading;
handled = true;
isLnkDirectory = true;
@@ -290,7 +288,7 @@ namespace SystemTrayMenu.DataClasses
return handled;
}
- private bool SetUrl()
+ private bool SetUrl(int level)
{
bool handled = false;
string iconFile = string.Empty;
@@ -303,7 +301,7 @@ namespace SystemTrayMenu.DataClasses
if (FileUrl.GetDefaultBrowserPath(out string browserPath))
{
FilePathIcon = browserPath;
- icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, MenuLevel == 0, out bool loading);
+ icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, level == 0, out bool loading);
IconLoading = loading;
handled = true;
}
@@ -311,7 +309,7 @@ namespace SystemTrayMenu.DataClasses
else if (File.Exists(iconFile))
{
FilePathIcon = iconFile;
- icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, MenuLevel == 0, out bool loading);
+ icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, level == 0, out bool loading);
IconLoading = loading;
handled = true;
}
@@ -330,12 +328,12 @@ namespace SystemTrayMenu.DataClasses
return handled;
}
- private bool SetSln()
+ private bool SetSln(int level)
{
bool handled = false;
try
{
- icon = IconReader.GetExtractAllIconsLastWithCache(TargetFilePathOrig, true, MenuLevel == 0, out bool loading);
+ icon = IconReader.GetExtractAllIconsLastWithCache(TargetFilePathOrig, true, level == 0, out bool loading);
IconLoading = loading;
handled = true;
}
diff --git a/NativeDllImport/CreateRoundRectRgn.cs b/NativeDllImport/CreateRoundRectRgn.cs
index 5d0e63c..c7d7d13 100644
--- a/NativeDllImport/CreateRoundRectRgn.cs
+++ b/NativeDllImport/CreateRoundRectRgn.cs
@@ -12,9 +12,20 @@ namespace SystemTrayMenu.DllImports
///
public static partial class NativeMethods
{
- public static IntPtr CreateRoundCorners(int width, int height, int widthEllipse, int heightEllipse)
+ public static bool GetRegionRoundCorners(int width, int height, int widthEllipse, int heightEllipse, out System.Drawing.Region region)
{
- return CreateRoundRectRgn(0, 0, width, height, widthEllipse, heightEllipse);
+ bool success = false;
+ region = null;
+
+ IntPtr handle = CreateRoundRectRgn(0, 0, width, height, widthEllipse, heightEllipse);
+ if (handle != IntPtr.Zero)
+ {
+ region = System.Drawing.Region.FromHrgn(handle);
+ DeleteObject(handle);
+ success = true;
+ }
+
+ return success;
}
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn", SetLastError = true, CharSet = CharSet.Unicode)]
diff --git a/NativeDllImport/DeleteObject.cs b/NativeDllImport/DeleteObject.cs
new file mode 100644
index 0000000..de69fe8
--- /dev/null
+++ b/NativeDllImport/DeleteObject.cs
@@ -0,0 +1,19 @@
+//
+// Copyright (c) PlaceholderCompany. All rights reserved.
+//
+
+namespace SystemTrayMenu.DllImports
+{
+ using System;
+ using System.Runtime.InteropServices;
+
+ ///
+ /// wraps the methodcalls to native windows dll's.
+ ///
+ public static partial class NativeMethods
+ {
+ [DllImport("gdi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
+ [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)]
+ private static extern int DeleteObject(IntPtr hIcon);
+ }
+}
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
index e5d374c..8c7c92f 100644
--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs
@@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.27.3")]
-[assembly: AssemblyFileVersion("1.0.27.3")]
+[assembly: AssemblyVersion("1.0.27.5")]
+[assembly: AssemblyFileVersion("1.0.27.5")]
diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs
index 02ae5c9..6406cae 100644
--- a/UserInterface/Menu.cs
+++ b/UserInterface/Menu.cs
@@ -482,8 +482,15 @@ namespace SystemTrayMenu.UserInterface
if (Properties.Settings.Default.RoundCorners)
{
- Region = Region.FromHrgn(NativeMethods.CreateRoundCorners(Width + 1, Height + 1, 15, 15));
- tableLayoutPanelMenu.Region = Region.FromHrgn(NativeMethods.CreateRoundCorners(Width - 1, Height - 1, 15, 15));
+ if (NativeMethods.GetRegionRoundCorners(Width + 1, Height + 1, 15, 15, out Region regionOutline))
+ {
+ Region = regionOutline;
+ }
+
+ if (NativeMethods.GetRegionRoundCorners(Width - 1, Height - 1, 15, 15, out Region region))
+ {
+ tableLayoutPanelMenu.Region = region;
+ }
}
}