diff --git a/Helpers/DirectoryHelpers.cs b/Helpers/DirectoryHelpers.cs index a78ecd2..afa08bb 100644 --- a/Helpers/DirectoryHelpers.cs +++ b/Helpers/DirectoryHelpers.cs @@ -204,7 +204,7 @@ namespace SystemTrayMenu.Helpers menuData.RowDatas.Add(new RowData(true, false, menuData.Level, directory)); } - foreach (string file in DirectoryBySearchPattern.GetFiles(path, Config.SearchPattern)) + foreach (string file in GetFilesBySearchPattern(path, Config.SearchPattern)) { if (worker?.CancellationPending == true) { @@ -223,7 +223,7 @@ namespace SystemTrayMenu.Helpers { try { - foreach (string file in DirectoryBySearchPattern.GetFiles(path, Config.SearchPattern)) + foreach (string file in GetFilesBySearchPattern(path, Config.SearchPattern)) { menuData.RowDatas.Add(new RowData(false, true, menuData.Level, file)); } @@ -246,5 +246,17 @@ namespace SystemTrayMenu.Helpers Log.Warn($"GetDirectoriesAndFilesRecursive path:'{path}'", ex); } } + + private static List GetFilesBySearchPattern(string path, string searchPatternCombined) + { + string[] searchPatterns = searchPatternCombined.Split('|'); + List files = new(); + foreach (string searchPattern in searchPatterns) + { + files.AddRange(Directory.GetFiles(path, searchPattern)); + } + + return files; + } } -} \ No newline at end of file +} diff --git a/NativeDllImport/CreatePopupMenu.cs b/NativeDllImport/CreatePopupMenu.cs deleted file mode 100644 index 5445297..0000000 --- a/NativeDllImport/CreatePopupMenu.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// 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 - { - public static IntPtr User32CreatePopupMenu() - { - return CreatePopupMenu(); - } - - // The CreatePopupMenu function creates a drop-down menu, submenu, or shortcut menu. The menu is initially empty. You can insert or append menu items by using the InsertMenuItem function. You can also use the InsertMenu function to insert menu items and the AppendMenu function to append menu items. - [DllImport("user32", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern IntPtr CreatePopupMenu(); - } -} diff --git a/NativeDllImport/DeleteObject.cs b/NativeDllImport/DeleteObject.cs deleted file mode 100644 index de69fe8..0000000 --- a/NativeDllImport/DeleteObject.cs +++ /dev/null @@ -1,19 +0,0 @@ -// -// 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/NativeDllImport/DestroyIcon.cs b/NativeDllImport/DestroyIcon.cs deleted file mode 100644 index 19cb236..0000000 --- a/NativeDllImport/DestroyIcon.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// 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 - { - public static void User32DestroyIcon(IntPtr hIcon) - { - _ = DestroyIcon(hIcon); - } - - [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern int DestroyIcon(IntPtr hIcon); - } -} diff --git a/NativeDllImport/DestroyMenu.cs b/NativeDllImport/DestroyMenu.cs deleted file mode 100644 index 2fd1818..0000000 --- a/NativeDllImport/DestroyMenu.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// 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 - { - public static bool User32DestroyMenu(IntPtr hMenu) - { - return DestroyMenu(hMenu); - } - - // The DestroyMenu function destroys the specified menu and frees any memory that the menu occupies. - [DllImport("user32", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern bool DestroyMenu(IntPtr hMenu); - } -} diff --git a/NativeDllImport/FindExecuteable.cs b/NativeDllImport/FindExecuteable.cs deleted file mode 100644 index 21c16a9..0000000 --- a/NativeDllImport/FindExecuteable.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright (c) PlaceholderCompany. All rights reserved. -// - -namespace SystemTrayMenu.DllImports -{ - using System.Runtime.InteropServices; - using System.Text; - - /// - /// wraps the methodcalls to native windows dll's. - /// - public static partial class NativeMethods - { - public static void Shell32FindExecutable(string lpFile, string lpDirectory, [Out] StringBuilder lpResult) - { - _ = FindExecutable(lpFile, lpDirectory, lpResult); - } - - [DllImport("shell32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern int FindExecutable(string lpFile, string lpDirectory, [Out] StringBuilder lpResult); - } -} diff --git a/NativeDllImport/FindWindow.cs b/NativeDllImport/FindWindow.cs deleted file mode 100644 index ce91672..0000000 --- a/NativeDllImport/FindWindow.cs +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright (c) PlaceholderCompany. All rights reserved. -// - -namespace SystemTrayMenu.DllImports -{ - using System; - using System.Runtime.InteropServices; - using System.Runtime.Versioning; - - /// - /// wraps the methodcalls to native windows dll's. - /// - public static partial class NativeMethods - { - public static IntPtr User32FindWindow(string? lpClassName, string? lpWindowName) - { - return FindWindow(lpClassName, lpWindowName); - } - - /// - /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindoww . - /// - [SupportedOSPlatform("windows")] - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern IntPtr FindWindow(string? lpClassName, string? lpWindowName); - } -} diff --git a/NativeDllImport/HotKey.cs b/NativeDllImport/HotKey.cs new file mode 100644 index 0000000..3447898 --- /dev/null +++ b/NativeDllImport/HotKey.cs @@ -0,0 +1,39 @@ +// +// Copyright (c) PlaceholderCompany. All rights reserved. +// + +namespace SystemTrayMenu.DllImports +{ + using System; + using System.Runtime.InteropServices; + using System.Runtime.Versioning; + using System.Text; + + /// + /// wraps the methodcalls to native windows dll's. + /// + public static partial class NativeMethods + { + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", EntryPoint = "RegisterHotKey", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool User32RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint virtualKeyCode); + + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", EntryPoint = "UnregisterHotKey", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [return: MarshalAs(UnmanagedType.Bool)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern bool User32UnregisterHotKey(IntPtr hWnd, int id); + + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", EntryPoint = "MapVirtualKey", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern uint User32MapVirtualKey(uint uCode, uint uMapType); + + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", EntryPoint = "GetKeyNameText", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern int User32GetKeyNameText(uint lParam, [Out] StringBuilder lpString, int nSize); + } +} diff --git a/NativeDllImport/GetIcon.cs b/NativeDllImport/Icon.cs similarity index 73% rename from NativeDllImport/GetIcon.cs rename to NativeDllImport/Icon.cs index 400c1d9..acea0b0 100644 --- a/NativeDllImport/GetIcon.cs +++ b/NativeDllImport/Icon.cs @@ -1,12 +1,13 @@ -// +// // Copyright (c) PlaceholderCompany. All rights reserved. // namespace SystemTrayMenu.DllImports { using System; - using System.Runtime.InteropServices; - + using System.Runtime.InteropServices; + using System.Runtime.Versioning; + /// /// wraps the methodcalls to native windows dll's. /// @@ -29,11 +30,17 @@ namespace SystemTrayMenu.DllImports /// i. /// flags. /// IntPtr. - [DllImport("comctl32", SetLastError = true, CharSet = CharSet.Unicode)] + [SupportedOSPlatform("windows")] + [DllImport("comctl32", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] internal static extern IntPtr ImageList_GetIcon( IntPtr himl, int i, - int flags); + int flags); + + [SupportedOSPlatform("windows")] + [DllImport("User32.dll", EntryPoint = "DestroyIcon", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern int User32DestroyIcon(IntPtr hIcon); } } diff --git a/NativeDllImport/IsTouchEnabled.cs b/NativeDllImport/IsTouchEnabled.cs deleted file mode 100644 index c15a342..0000000 --- a/NativeDllImport/IsTouchEnabled.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (c) PlaceholderCompany. All rights reserved. -// - -namespace SystemTrayMenu.DllImports -{ - using System.Runtime.InteropServices; - - /// - /// wraps the methodcalls to native windows dll's. - /// - public static partial class NativeMethods - { - public static bool IsTouchEnabled() - { - const int MAXTOUCHES_INDEX = 95; - int maxTouches = GetSystemMetrics(MAXTOUCHES_INDEX); - - return maxTouches > 0; - } - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern int GetSystemMetrics(int nIndex); - } -} diff --git a/NativeDllImport/Menu.cs b/NativeDllImport/Menu.cs new file mode 100644 index 0000000..3deab49 --- /dev/null +++ b/NativeDllImport/Menu.cs @@ -0,0 +1,69 @@ +// +// Copyright (c) PlaceholderCompany. All rights reserved. +// + +namespace SystemTrayMenu.DllImports +{ + using System; + using System.Runtime.InteropServices; + using System.Runtime.Versioning; + + /// + /// wraps the methodcalls to native windows dll's. + /// + public static partial class NativeMethods + { + /// + /// Specifies how TrackPopupMenuEx positions the shortcut menu horizontally. + /// + [Flags] + internal enum TPM : uint + { + LEFTBUTTON = 0x0000, // LEFTALIGN = 0x0000, // TOPALIGN = 0x0000, // HORIZONTAL = 0x0000, + RIGHTBUTTON = 0x0002, + CENTERALIGN = 0x0004, + RIGHTALIGN = 0x0008, + VCENTERALIGN = 0x0010, + BOTTOMALIGN = 0x0020, + VERTICAL = 0x0040, + NONOTIFY = 0x0080, + RETURNCMD = 0x0100, + RECURSE = 0x0001, + HORPOSANIMATION = 0x0400, + HORNEGANIMATION = 0x0800, + VERPOSANIMATION = 0x1000, + VERNEGANIMATION = 0x2000, + NOANIMATION = 0x4000, + LAYOUTRTL = 0x8000, + } + + // The CreatePopupMenu function creates a drop-down menu, submenu, or shortcut menu. The menu is initially empty. You can insert or append menu items by using the InsertMenuItem function. You can also use the InsertMenu function to insert menu items and the AppendMenu function to append menu items. + [SupportedOSPlatform("windows")] + [DllImport("user32", EntryPoint = "CreatePopupMenu", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern IntPtr User32CreatePopupMenu(); + + // The DestroyMenu function destroys the specified menu and frees any memory that the menu occupies. + [SupportedOSPlatform("windows")] + [DllImport("user32", EntryPoint = "DestroyMenu", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern bool User32DestroyMenu(IntPtr hMenu); + + /// + /// user32 TrackPopupMenuEx. + /// The TrackPopupMenuEx function displays a shortcut menu at the specified location and + /// tracks the selection of items on the shortcut menu. The shortcut menu can appear anywhere on the screen. + /// + /// hmenu. + /// flags. + /// x. + /// y. + /// hwnd. + /// lptpm. + /// uint. + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", EntryPoint = "TrackPopupMenuEx", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern uint User32TrackPopupMenuEx(IntPtr hmenu, TPM flags, int x, int y, IntPtr hwnd, IntPtr lptpm); + } +} diff --git a/NativeDllImport/RegisterHotKey.cs b/NativeDllImport/RegisterHotKey.cs deleted file mode 100644 index 233ffb2..0000000 --- a/NativeDllImport/RegisterHotKey.cs +++ /dev/null @@ -1,54 +0,0 @@ -// -// Copyright (c) PlaceholderCompany. All rights reserved. -// - -namespace SystemTrayMenu.DllImports -{ - using System; - using System.Runtime.InteropServices; - using System.Text; - - /// - /// wraps the methodcalls to native windows dll's. - /// - public static partial class NativeMethods - { - public static bool User32RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk) - { - return RegisterHotKey(hWnd, id, fsModifiers, vk); - } - - public static bool User32UnregisterHotKey(IntPtr hWnd, int id) - { - return UnregisterHotKey(hWnd, id); - } - - public static uint User32MapVirtualKey(uint uCode, uint uMapType) - { - return MapVirtualKey(uCode, uMapType); - } - - public static int User32GetKeyNameText(uint lParam, [Out] StringBuilder lpString, int nSize) - { - return GetKeyNameText(lParam, lpString, nSize); - } - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint virtualKeyCode); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [return: MarshalAs(UnmanagedType.Bool)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern bool UnregisterHotKey(IntPtr hWnd, int id); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern uint MapVirtualKey(uint uCode, uint uMapType); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern int GetKeyNameText(uint lParam, [Out] StringBuilder lpString, int nSize); - } -} diff --git a/NativeDllImport/SHGetDesktopFolder.cs b/NativeDllImport/SHGetDesktopFolder.cs deleted file mode 100644 index 30d6f4f..0000000 --- a/NativeDllImport/SHGetDesktopFolder.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// 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 - { - public static int Shell32SHGetDesktopFolder(out IntPtr ppshf) - { - return SHGetDesktopFolder(out ppshf); - } - - // Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace. - [DllImport("shell32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern int SHGetDesktopFolder(out IntPtr ppshf); - } -} diff --git a/NativeDllImport/SHGetFileInfo.cs b/NativeDllImport/SHGetFileInfo.cs deleted file mode 100644 index ea7fdbb..0000000 --- a/NativeDllImport/SHGetFileInfo.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// 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 - { - private const int maxPath = 256; - - internal static IntPtr Shell32SHGetFileInfo( - string pszPath, - uint dwFileAttributes, - ref SHFILEINFO psfi, - uint cbFileInfo, - uint uFlags) - { - return SHGetFileInfo( - pszPath, - dwFileAttributes, - ref psfi, - cbFileInfo, - uFlags); - } - - [DllImport("Shell32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern IntPtr SHGetFileInfo( - string pszPath, - uint dwFileAttributes, - ref SHFILEINFO psfi, - uint cbFileInfo, - uint uFlags); - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] - - internal struct SHFILEINFO - { - public const int NAMESIZE = 80; - public IntPtr hIcon; - public int iIcon; - public uint dwAttributes; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = maxPath)] - public string szDisplayName; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NAMESIZE)] - public string szTypeName; - } - } -} diff --git a/NativeDllImport/SHGetFolderPath.cs b/NativeDllImport/SHGetFolderPath.cs deleted file mode 100644 index 9875203..0000000 --- a/NativeDllImport/SHGetFolderPath.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// Copyright (c) PlaceholderCompany. All rights reserved. -// - -namespace SystemTrayMenu.DllImports -{ - using System; - using System.Runtime.InteropServices; - using System.Text; - - /// - /// wraps the methodcalls to native windows dll's. - /// - public static partial class NativeMethods - { - public static int ShfolderSHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath) - { - return SHGetFolderPath(hwndOwner, nFolder, hToken, dwFlags, lpszPath); - } - - [DllImport("shfolder.dll", SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath); - } -} diff --git a/NativeDllImport/Screen.cs b/NativeDllImport/Screen.cs index a45c832..0ccf795 100644 --- a/NativeDllImport/Screen.cs +++ b/NativeDllImport/Screen.cs @@ -2,7 +2,7 @@ // Copyright (c) PlaceholderCompany. All rights reserved. // // -// Copyright (c) 2022-2022 Peter Kirmeier +// Copyright (c) 2022-2023 Peter Kirmeier namespace SystemTrayMenu.DllImports { @@ -17,6 +17,19 @@ namespace SystemTrayMenu.DllImports /// public static partial class NativeMethods { + public static bool IsTouchEnabled() + { + const int MAXTOUCHES_INDEX = 95; + int maxTouches = GetSystemMetrics(MAXTOUCHES_INDEX); + + return maxTouches > 0; + } + + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + private static extern int GetSystemMetrics(int nIndex); + public static class Screen { private static Point LastCursorPosition = new Point(0, 0); @@ -112,14 +125,16 @@ namespace SystemTrayMenu.DllImports /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors . /// [SupportedOSPlatform("windows")] - [DllImport("user32.dll", CharSet = CharSet.Unicode)] + [DllImport("user32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] public static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, MonitorEnumDelegate lpfnEnum, IntPtr dwData); /// /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getcursorpos . /// [SupportedOSPlatform("windows")] - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] public static extern bool GetCursorPos(out POINT lpPoint); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] diff --git a/UserInterface/FolderBrowseDialog/NativeMethods.cs b/NativeDllImport/ShellInterfacesCOM.cs similarity index 94% rename from UserInterface/FolderBrowseDialog/NativeMethods.cs rename to NativeDllImport/ShellInterfacesCOM.cs index 303d5a8..e4e333e 100644 --- a/UserInterface/FolderBrowseDialog/NativeMethods.cs +++ b/NativeDllImport/ShellInterfacesCOM.cs @@ -1,14 +1,15 @@ -// +// // Copyright (c) PlaceholderCompany. All rights reserved. // -namespace SystemTrayMenu.UserInterface.FolderBrowseDialog +namespace SystemTrayMenu.DllImports { using System; using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - - internal static class NativeMethods + using System.Runtime.InteropServices; + using System.Runtime.Versioning; + + public static partial class NativeMethods { public const uint FOS_PICKFOLDERS = 0x00000020; public const uint FOS_FORCEFILESYSTEM = 0x00000040; @@ -20,7 +21,8 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog public const uint SIGDN_FILESYSPATH = 0x80058000; - [ComImport] + [ComImport] + [SupportedOSPlatform("windows")] [Guid("42F85136-DB7E-439C-85F1-E4075D135FC8")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] internal interface IFileDialog @@ -102,7 +104,8 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog uint SetFilter([MarshalAs(UnmanagedType.Interface)] IntPtr pFilter); } - [ComImport] + [ComImport] + [SupportedOSPlatform("windows")] [Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] internal interface IShellItem @@ -125,9 +128,10 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] uint Compare([In, MarshalAs(UnmanagedType.Interface)] IShellItem psi, [In] uint hint, out int piOrder); - } - - [DllImport("shell32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + } + + [SupportedOSPlatform("windows")] + [DllImport("shell32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] internal static extern int SHCreateItemFromParsingName( [MarshalAs(UnmanagedType.LPWStr)] string pszPath, @@ -135,7 +139,8 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out IShellItem ppv); - [ComImport] + [ComImport] + [SupportedOSPlatform("windows")] [ClassInterface(ClassInterfaceType.None)] [TypeLibType(TypeLibTypeFlags.FCanCreate)] [Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7")] diff --git a/NativeDllImport/ShellWindowsApi.cs b/NativeDllImport/ShellWindowsApi.cs new file mode 100644 index 0000000..a77720e --- /dev/null +++ b/NativeDllImport/ShellWindowsApi.cs @@ -0,0 +1,59 @@ +// +// Copyright (c) PlaceholderCompany. All rights reserved. +// + +namespace SystemTrayMenu.DllImports +{ + using System; + using System.Runtime.InteropServices; + using System.Runtime.Versioning; + using System.Text; + + /// + /// wraps the methodcalls to native windows dll's. + /// + public static partial class NativeMethods + { + [SupportedOSPlatform("windows")] + [DllImport("Shell32.dll", EntryPoint = "SHGetFileInfo", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern IntPtr Shell32SHGetFileInfo( + string pszPath, + uint dwFileAttributes, + ref SHFILEINFO psfi, + uint cbFileInfo, + uint uFlags); + + // Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace. + [SupportedOSPlatform("windows")] + [DllImport("shell32.dll", EntryPoint = "SHGetDesktopFolder", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern int Shell32SHGetDesktopFolder(out IntPtr ppshf); + + [SupportedOSPlatform("windows")] + [DllImport("shlwapi.dll", EntryPoint = "StrCmpLogicalW", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern int ShlwapiStrCmpLogicalW(string x, string y); + + // Takes a STRRET structure returned by IShellFolder::GetDisplayNameOf, converts it to a string, and places the result in a buffer. + [SupportedOSPlatform("windows")] + [DllImport("shlwapi.dll", EntryPoint = "StrRetToBuf", ExactSpelling = false, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern int ShlwapiStrRetToBuf(IntPtr pstr, IntPtr pidl, StringBuilder pszBuf, int cchBuf); + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + internal struct SHFILEINFO + { + public IntPtr hIcon; + public int iIcon; + public uint dwAttributes; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] + public string szDisplayName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NAMESIZE)] + public string szTypeName; + + private const int NAMESIZE = 80; + private const int MAX_PATH = 256; + } + } +} diff --git a/NativeDllImport/StrCmpLogicalW.cs b/NativeDllImport/StrCmpLogicalW.cs deleted file mode 100644 index 9ae6ade..0000000 --- a/NativeDllImport/StrCmpLogicalW.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// Copyright (c) PlaceholderCompany. All rights reserved. -// - -namespace SystemTrayMenu.DllImports -{ - using System.Runtime.InteropServices; - using System.Runtime.Versioning; - - /// - /// wraps the methodcalls to native windows dll's. - /// - public static partial class NativeMethods - { - public static int ShlwapiStrCmpLogicalW(string x, string y) - { - return StrCmpLogicalW(x, y); - } - - [SupportedOSPlatform("windows")] - [DllImport("shlwapi.dll", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern int StrCmpLogicalW(string x, string y); - } -} diff --git a/NativeDllImport/StrRetToBuf.cs b/NativeDllImport/StrRetToBuf.cs deleted file mode 100644 index ba412bb..0000000 --- a/NativeDllImport/StrRetToBuf.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (c) PlaceholderCompany. All rights reserved. -// - -namespace SystemTrayMenu.DllImports -{ - using System; - using System.Runtime.InteropServices; - using System.Text; - - /// - /// wraps the methodcalls to native windows dll's. - /// - public static partial class NativeMethods - { - public static int ShlwapiStrRetToBuf(IntPtr pstr, IntPtr pidl, StringBuilder pszBuf, int cchBuf) - { - return StrRetToBuf(pstr, pidl, pszBuf, cchBuf); - } - - // Takes a STRRET structure returned by IShellFolder::GetDisplayNameOf, converts it to a string, and places the result in a buffer. - [DllImport("shlwapi.dll", EntryPoint = "StrRetToBuf", ExactSpelling = false, SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern int StrRetToBuf(IntPtr pstr, IntPtr pidl, StringBuilder pszBuf, int cchBuf); - } -} diff --git a/NativeDllImport/SHAppBarMessage.cs b/NativeDllImport/TaskBar.cs similarity index 80% rename from NativeDllImport/SHAppBarMessage.cs rename to NativeDllImport/TaskBar.cs index f29da4f..e1c060b 100644 --- a/NativeDllImport/SHAppBarMessage.cs +++ b/NativeDllImport/TaskBar.cs @@ -1,12 +1,13 @@ -// +// // Copyright (c) PlaceholderCompany. All rights reserved. // namespace SystemTrayMenu.DllImports { using System; - using System.Runtime.InteropServices; - + using System.Runtime.InteropServices; + using System.Runtime.Versioning; + /// /// wraps the methodcalls to native windows dll's. /// @@ -34,15 +35,11 @@ namespace SystemTrayMenu.DllImports Right = 2, Bottom = 3, } - - internal static IntPtr Shell32SHAppBarMessage(ABM dwMessage, [In] ref APPBARDATA pData) - { - return SHAppBarMessage(dwMessage, ref pData); - } - - [DllImport("shell32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + + [SupportedOSPlatform("windows")] + [DllImport("shell32.dll", EntryPoint = "SHAppBarMessage", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern IntPtr SHAppBarMessage(ABM dwMessage, [In] ref APPBARDATA pData); + internal static extern IntPtr Shell32SHAppBarMessage(ABM dwMessage, [In] ref APPBARDATA pData); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal struct APPBARDATA diff --git a/NativeDllImport/TrackPopupMenuEx.cs b/NativeDllImport/TrackPopupMenuEx.cs deleted file mode 100644 index 59a0649..0000000 --- a/NativeDllImport/TrackPopupMenuEx.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// 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 - { - /// - /// Specifies how TrackPopupMenuEx positions the shortcut menu horizontally. - /// - [Flags] - internal enum TPM : uint - { - LEFTBUTTON = 0x0000, // LEFTALIGN = 0x0000, // TOPALIGN = 0x0000, // HORIZONTAL = 0x0000, - RIGHTBUTTON = 0x0002, - CENTERALIGN = 0x0004, - RIGHTALIGN = 0x0008, - VCENTERALIGN = 0x0010, - BOTTOMALIGN = 0x0020, - VERTICAL = 0x0040, - NONOTIFY = 0x0080, - RETURNCMD = 0x0100, - RECURSE = 0x0001, - HORPOSANIMATION = 0x0400, - HORNEGANIMATION = 0x0800, - VERPOSANIMATION = 0x1000, - VERNEGANIMATION = 0x2000, - NOANIMATION = 0x4000, - LAYOUTRTL = 0x8000, - } - - /// - /// user32 TrackPopupMenuEx. - /// - /// hmenu. - /// flags. - /// x. - /// y. - /// hwnd. - /// lptpm. - /// uint. - internal static uint User32TrackPopupMenuEx(IntPtr hmenu, TPM flags, int x, int y, IntPtr hwnd, IntPtr lptpm) - { - return TrackPopupMenuEx(hmenu, flags, x, y, hwnd, lptpm); - } - - // The TrackPopupMenuEx function displays a shortcut menu at the specified location and tracks the selection of items on the shortcut menu. The shortcut menu can appear anywhere on the screen. - [DllImport("user32.dll", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode)] - [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] - private static extern uint TrackPopupMenuEx(IntPtr hmenu, TPM flags, int x, int y, IntPtr hwnd, IntPtr lptpm); - } -} diff --git a/NativeDllImport/ShowWindow.cs b/NativeDllImport/Window.cs similarity index 70% rename from NativeDllImport/ShowWindow.cs rename to NativeDllImport/Window.cs index 570e479..175daa5 100644 --- a/NativeDllImport/ShowWindow.cs +++ b/NativeDllImport/Window.cs @@ -1,8 +1,8 @@ -// +// // Copyright (c) PlaceholderCompany. All rights reserved. // // -// Copyright (c) 2022-2022 Peter Kirmeier +// Copyright (c) 2022-2023 Peter Kirmeier namespace SystemTrayMenu.DllImports { @@ -38,11 +38,23 @@ namespace SystemTrayMenu.DllImports } } + /// + /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindoww . + /// + /// The class name or a class atom. + /// The window name. + /// Handle to the window or NULL on failure. + [SupportedOSPlatform("windows")] + [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] + internal static extern IntPtr User32FindWindow(string? lpClassName, string? lpWindowName); + /// /// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongw . /// [SupportedOSPlatform("windows")] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex); /// @@ -50,6 +62,7 @@ namespace SystemTrayMenu.DllImports /// [SupportedOSPlatform("windows")] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex); /// @@ -57,6 +70,7 @@ namespace SystemTrayMenu.DllImports /// [SupportedOSPlatform("windows")] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong); /// @@ -64,6 +78,7 @@ namespace SystemTrayMenu.DllImports /// [SupportedOSPlatform("windows")] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] + [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); } } diff --git a/UserInterface/AppContextMenu.cs b/UserInterface/AppContextMenu.cs index 0d39559..fa7ed9a 100644 --- a/UserInterface/AppContextMenu.cs +++ b/UserInterface/AppContextMenu.cs @@ -2,7 +2,7 @@ // Copyright (c) PlaceholderCompany. All rights reserved. // -namespace SystemTrayMenu.Helpers +namespace SystemTrayMenu.UserInterface { using System; using System.Diagnostics; @@ -11,7 +11,6 @@ namespace SystemTrayMenu.Helpers using System.Windows.Threading; using H.NotifyIcon.Core; using SystemTrayMenu.Helpers.Updater; - using SystemTrayMenu.UserInterface; using SystemTrayMenu.Utilities; internal class AppContextMenu diff --git a/UserInterface/AppNotifyIcon.cs b/UserInterface/AppNotifyIcon.cs index ef59cad..987e90a 100644 --- a/UserInterface/AppNotifyIcon.cs +++ b/UserInterface/AppNotifyIcon.cs @@ -7,7 +7,6 @@ namespace SystemTrayMenu.UserInterface using System; using System.Windows.Threading; using H.NotifyIcon.Core; - using SystemTrayMenu.Helpers; internal class AppNotifyIcon : IDisposable { diff --git a/UserInterface/FolderBrowseDialog/FolderDialog.cs b/UserInterface/FolderBrowseDialog/FolderDialog.cs index ab5425e..50ae2ab 100644 --- a/UserInterface/FolderBrowseDialog/FolderDialog.cs +++ b/UserInterface/FolderBrowseDialog/FolderDialog.cs @@ -9,6 +9,7 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog using System.Runtime.Versioning; using System.Windows; using System.Windows.Interop; + using SystemTrayMenu.DllImports; using SystemTrayMenu.Utilities; public class FolderDialog : IFolderDialog, IDisposable diff --git a/UserInterface/ShellContextMenu/ShellContextMenu.cs b/UserInterface/ShellContextMenu.cs similarity index 100% rename from UserInterface/ShellContextMenu/ShellContextMenu.cs rename to UserInterface/ShellContextMenu.cs diff --git a/Utilities/File/DirectoryBySearchPattern.cs b/Utilities/File/DirectoryBySearchPattern.cs deleted file mode 100644 index 966659e..0000000 --- a/Utilities/File/DirectoryBySearchPattern.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright (c) PlaceholderCompany. All rights reserved. -// -// see also: https://www.codeproject.com/Articles/2532/Obtaining-and-managing-file-and-folder-icons-using. - -namespace SystemTrayMenu.Utilities -{ - using System.Collections.Generic; - - public static class DirectoryBySearchPattern - { - public static List GetFiles(string path, string searchPatternCombined) - { - string[] searchPatterns = searchPatternCombined.Split('|'); - List files = new(); - foreach (string searchPattern in searchPatterns) - { - files.AddRange(System.IO.Directory.GetFiles(path, searchPattern)); - } - - return files; - } - } -} \ No newline at end of file