From a1a408da1ddf9328a4d7372fe2c24bcd3cf23357 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sun, 6 Dec 2020 16:54:06 +0100 Subject: [PATCH] improved setup dialog --- mpv.net/Native/StockIcon.cs | 131 ++++++++++++++++++++++++++++++++ mpv.net/WPF/SetupWindow.xaml | 28 +++++-- mpv.net/WPF/SetupWindow.xaml.cs | 34 ++++++++- mpv.net/WPF/WPF.cs | 5 +- mpv.net/WinForms/MainForm.cs | 3 + mpv.net/mpv.net.csproj | 1 + 6 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 mpv.net/Native/StockIcon.cs diff --git a/mpv.net/Native/StockIcon.cs b/mpv.net/Native/StockIcon.cs new file mode 100644 index 0000000..f7db5be --- /dev/null +++ b/mpv.net/Native/StockIcon.cs @@ -0,0 +1,131 @@ + +using System; +using System.Runtime.InteropServices; + +public class StockIcon +{ + [DllImport("shell32.dll")] + public static extern int SHGetStockIconInfo(SHSTOCKICONID siid, SHSTOCKICONFLAGS uFlags, ref SHSTOCKICONINFO info); + + [DllImport("user32.dll")] + public static extern bool DestroyIcon(IntPtr handle); + + public static IntPtr GetIcon(SHSTOCKICONID identifier, SHSTOCKICONFLAGS flags) + { + SHSTOCKICONINFO info = new SHSTOCKICONINFO(); + info.cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(SHSTOCKICONINFO))); + Marshal.ThrowExceptionForHR(SHGetStockIconInfo(identifier, flags, ref info)); + return info.hIcon; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct SHSTOCKICONINFO + { + public uint cbSize; + public IntPtr hIcon; + int iSysImageIndex; + int iIcon; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] + string szPath; + } + + public enum SHSTOCKICONFLAGS : uint + { + SHGSI_ICONLOCATION = 0, + SHGSI_ICON = 0x000000100, + SHGSI_SYSICONINDEX = 0x000004000, + SHGSI_LINKOVERLAY = 0x000008000, + SHGSI_SELECTED = 0x000010000, + SHGSI_LARGEICON = 0x000000000, + SHGSI_SMALLICON = 0x000000001, + SHGSI_SHELLICONSIZE = 0x000000004 + } + + public enum SHSTOCKICONID : uint + { + DocumentNotAssociated = 0, + DocumentAssociated = 1, + Application = 2, + Folder = 3, + FolderOpen = 4, + Drive525 = 5, + Drive35 = 6, + DriveRemove = 7, + DriveFixed = 8, + DriveNetwork = 9, + DriveNetworkDisabled = 10, + DriveCD = 11, + DriveRAM = 12, + World = 13, + Server = 15, + Printer = 16, + MyNetwork = 17, + Find = 22, + Help = 23, + Share = 28, + Link = 29, + SlowFile = 30, + Recycler = 31, + RecyclerFull = 32, + MediaCDAudio = 40, + Lock = 47, + AutoList = 49, + PrinterNet = 50, + ServerShare = 51, + PrinterFax = 52, + PrinterFaxNet = 53, + PrinterFile = 54, + Stack = 55, + MediaSVCD = 56, + StuffedFolder = 57, + DriveUnknown = 58, + DriveDVD = 59, + MediaDVD = 60, + MediaDVDRAM = 61, + MediaDVDRW = 62, + MediaDVDR = 63, + MediaDVDROM = 64, + MediaCDAudioPlus = 65, + MediaCDRW = 66, + MediaCDR = 67, + MediaCDBurn = 68, + MediaBlankCD = 69, + MediaCDROM = 70, + AudioFiles = 71, + ImageFiles = 72, + VideoFiles = 73, + MixedFiles = 74, + FolderBack = 75, + FolderFront = 76, + Shield = 77, + Warning = 78, + Info = 79, + Error = 80, + Key = 81, + Software = 82, + Rename = 83, + Delete = 84, + MediaAudioDVD = 85, + MediaMovieDVD = 86, + MediaEnhancedCD = 87, + MediaEnhancedDVD = 88, + MediaHDDVD = 89, + MediaBluRay = 90, + MediaVCD = 91, + MediaDVDPlusR = 92, + MediaDVDPlusRW = 93, + DesktopPC = 94, + MobilePC = 95, + Users = 96, + MediaSmartMedia = 97, + MediaCompactFlash = 98, + DeviceCellPhone = 99, + DeviceCamera = 100, + DeviceVideoCamera = 101, + DeviceAudioPlayer = 102, + NetworkConnect = 103, + Internet = 104, + ZipFile = 105, + Settings = 106 + } +} diff --git a/mpv.net/WPF/SetupWindow.xaml b/mpv.net/WPF/SetupWindow.xaml index a16ba01..b4dc788 100644 --- a/mpv.net/WPF/SetupWindow.xaml +++ b/mpv.net/WPF/SetupWindow.xaml @@ -15,19 +15,31 @@ + + + + - - - - - - + + + + + + \ No newline at end of file diff --git a/mpv.net/WPF/SetupWindow.xaml.cs b/mpv.net/WPF/SetupWindow.xaml.cs index 0726730..7c5d24a 100644 --- a/mpv.net/WPF/SetupWindow.xaml.cs +++ b/mpv.net/WPF/SetupWindow.xaml.cs @@ -2,15 +2,34 @@ using System; using System.Diagnostics; using System.Windows; +using System.Windows.Media.Imaging; +using System.Windows.Interop; using WinForms = System.Windows.Forms; +using static StockIcon; + namespace mpvnet { public partial class SetupWindow : Window { public SetupWindow() => InitializeComponent(); + static BitmapSource _ShieldIcon; + + public static BitmapSource ShieldIcon { + get { + if (_ShieldIcon == null) + { + IntPtr icon = GetIcon(SHSTOCKICONID.Shield, SHSTOCKICONFLAGS.SHGSI_ICON); + _ShieldIcon = Imaging.CreateBitmapSourceFromHIcon( + icon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); + DestroyIcon(icon); + } + return _ShieldIcon; + } + } + void RegisterFileAssociations(string value) { try @@ -60,5 +79,18 @@ namespace mpvnet else Msg.ShowWarning("Path was not containing mpv.net."); } + + void aaa() + { + BitmapSource shieldSource = null; + IntPtr icon = GetIcon(SHSTOCKICONID.Shield, SHSTOCKICONFLAGS.SHGSI_LARGEICON); + shieldSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( + icon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); + DestroyIcon(icon); + //shieldSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( + // System.Drawing.SystemIcons.Shield.Handle, + // Int32Rect.Empty, + // BitmapSizeOptions.FromEmptyOptions()); + } } -} \ No newline at end of file +} diff --git a/mpv.net/WPF/WPF.cs b/mpv.net/WPF/WPF.cs index 980e6b9..853552b 100644 --- a/mpv.net/WPF/WPF.cs +++ b/mpv.net/WPF/WPF.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Windows; namespace WPF @@ -17,4 +18,4 @@ namespace WPF } } } -} \ No newline at end of file +} diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 27b63d5..be3e426 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -814,6 +814,9 @@ namespace mpvnet core.LoadScripts(); Task.Run(() => App.Extension = new Extension()); ShownTickCount = Environment.TickCount; + + SetupWindow win = new SetupWindow(); + win.Show(); } protected override void OnActivated(EventArgs e) diff --git a/mpv.net/mpv.net.csproj b/mpv.net/mpv.net.csproj index d1e7c2d..b8bc0e4 100644 --- a/mpv.net/mpv.net.csproj +++ b/mpv.net/mpv.net.csproj @@ -134,6 +134,7 @@ + SearchTextBoxUserControl.xaml