diff --git a/UnitTests/Windows.Forms.App/Form1.Designer.cs b/UnitTests/Windows.Forms.App/Form1.Designer.cs index b5e8bf8a..e875485f 100644 --- a/UnitTests/Windows.Forms.App/Form1.Designer.cs +++ b/UnitTests/Windows.Forms.App/Form1.Designer.cs @@ -49,10 +49,12 @@ this.themedPanel1 = new Vanara.Windows.Forms.ThemedPanel(); this.themedImageDraw1 = new Vanara.Windows.Forms.ThemedImageDraw(); this.ipAddressBox1 = new Vanara.Windows.Forms.IPAddressBox(); + this.taskbarButton1 = new Vanara.Windows.Shell.TaskbarButton(this.components); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBarEx1)).BeginInit(); this.contextMenuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.vistaControlExtender1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.taskbarButton1)).BeginInit(); this.SuspendLayout(); // // groupBox1 @@ -135,24 +137,24 @@ this.twoToolStripMenuItem, this.threeToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(105, 70); + this.contextMenuStrip1.Size = new System.Drawing.Size(104, 70); // // oneToolStripMenuItem // this.oneToolStripMenuItem.Name = "oneToolStripMenuItem"; - this.oneToolStripMenuItem.Size = new System.Drawing.Size(104, 22); + this.oneToolStripMenuItem.Size = new System.Drawing.Size(103, 22); this.oneToolStripMenuItem.Text = "One"; // // twoToolStripMenuItem // this.twoToolStripMenuItem.Name = "twoToolStripMenuItem"; - this.twoToolStripMenuItem.Size = new System.Drawing.Size(104, 22); + this.twoToolStripMenuItem.Size = new System.Drawing.Size(103, 22); this.twoToolStripMenuItem.Text = "Two"; // // threeToolStripMenuItem // this.threeToolStripMenuItem.Name = "threeToolStripMenuItem"; - this.threeToolStripMenuItem.Size = new System.Drawing.Size(104, 22); + this.threeToolStripMenuItem.Size = new System.Drawing.Size(103, 22); this.threeToolStripMenuItem.Text = "Three"; // // enumComboBox1 @@ -246,11 +248,14 @@ this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.glassExtenderProvider1.SetGlassMargins(this, new System.Windows.Forms.Padding(0, 85, 0, 0)); this.Name = "Form1"; - this.Text = "Form1"; + this.Text = "Vanara.Windows.Forms Test App"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); this.groupBox1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.trackBarEx1)).EndInit(); this.contextMenuStrip1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.vistaControlExtender1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.taskbarButton1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -277,6 +282,7 @@ private Vanara.Windows.Forms.ThemedPanel themedPanel1; private Vanara.Windows.Forms.ThemedImageDraw themedImageDraw1; private Vanara.Windows.Forms.IPAddressBox ipAddressBox1; + private Vanara.Windows.Shell.TaskbarButton taskbarButton1; } } diff --git a/UnitTests/Windows.Forms.App/Form1.cs b/UnitTests/Windows.Forms.App/Form1.cs index 31ac9fec..3311d31e 100644 --- a/UnitTests/Windows.Forms.App/Form1.cs +++ b/UnitTests/Windows.Forms.App/Form1.cs @@ -1,14 +1,22 @@ using System; +using System.Collections.Generic; using System.Data; +using System.IO; using System.Linq; using System.Reflection; using System.Windows.Forms; +using Vanara.PInvoke; +using Vanara.Windows.Shell; namespace Windows.Forms.App { public partial class Form1 : Form { + private const string appId = "Windows.Forms.App"; + private const bool systemWide = false; + private static readonly string[] extensions = new[] { ".dmy" }; private object currentDlg; + private List tempFiles = new List(); public Form1() { @@ -16,7 +24,7 @@ namespace Windows.Forms.App FillComboWithDialogs(dlgCombo); } - private static void FillComboWithDialogs(ComboBox cb) => cb.Items.AddRange(Assembly.GetAssembly(typeof(Vanara.Windows.Forms.AccessControlEditorDialog)).GetTypes().Where(t => !t.IsNested && typeof(CommonDialog).IsAssignableFrom(t) || typeof(Form).IsAssignableFrom(t)).ToArray()); + private static void FillComboWithDialogs(ComboBox cb) => cb.Items.AddRange(Assembly.GetAssembly(typeof(Vanara.Windows.Forms.AccessControlEditorDialog)).GetTypes().Where(t => t.IsPublic && !t.IsNested && typeof(CommonDialog).IsAssignableFrom(t) || typeof(Form).IsAssignableFrom(t)).ToArray()); private void button1_Click(object sender, EventArgs e) { @@ -39,5 +47,35 @@ namespace Windows.Forms.App currentDlg = dlgCombo.SelectedItem is null ? null : Activator.CreateInstance((Type)dlgCombo.SelectedItem); propertyGrid1.SelectedObject = currentDlg; } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + // Remove temp files + foreach (var n in tempFiles) + File.Delete(n); + + // Unregister app + ProgId.Unregister(appId, true, systemWide); + } + + private void Form1_Load(object sender, EventArgs e) + { + // Register app + using (var progId = ProgId.Register(appId, Text, systemWide)) + { + progId.Verbs.Add("open", "Open", $"{Application.ExecutablePath} %1", true); + foreach (var ext in extensions) + progId.FileTypeAssociations.Add(ext); + } + + // Create temp files + var tempCount = 4; + for (var i = 0; i < tempCount; i++) + { + var nfn = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), $"____File{i:D4}{extensions[0]}"); + File.WriteAllText(nfn, "dummy"); + tempFiles.Add(nfn); + } + } } } \ No newline at end of file diff --git a/UnitTests/Windows.Forms.App/Form1.resx b/UnitTests/Windows.Forms.App/Form1.resx index aa75ea52..46ba1595 100644 --- a/UnitTests/Windows.Forms.App/Form1.resx +++ b/UnitTests/Windows.Forms.App/Form1.resx @@ -123,6 +123,9 @@ 366, 17 + + 17, 17 + @@ -173,4 +176,7 @@ ZnOqQcUYOEtLS2/wiY5P84GBgZdkTAzcmr9rHX1M8zEnawAAAABJRU5ErkJggg== + + 521, 17 + \ No newline at end of file diff --git a/UnitTests/Windows.Forms.App/Windows.Forms.App.csproj b/UnitTests/Windows.Forms.App/Windows.Forms.App.csproj index b2729699..35069e43 100644 --- a/UnitTests/Windows.Forms.App/Windows.Forms.App.csproj +++ b/UnitTests/Windows.Forms.App/Windows.Forms.App.csproj @@ -81,6 +81,18 @@ {241f73ee-9298-45c9-b869-a045dff94c03} Vanara.Core + + {a5e519e9-feba-4fe3-93a5-b8269bef72f4} + Vanara.PInvoke.Shared + + + {3226020f-4c9d-41b3-ac8a-2bc9fd064cd8} + Vanara.PInvoke.Shell32 + + + {30FD6779-6549-449E-880A-695815EB89B0} + Vanara.PInvoke.ShlwApi + {51986cd3-eeda-4369-93a4-255512548f68} Vanara.Windows.Forms diff --git a/UnitTests/Windows.Shell/ShellLinkTests.cs b/UnitTests/Windows.Shell/ShellLinkTests.cs new file mode 100644 index 00000000..54164b46 --- /dev/null +++ b/UnitTests/Windows.Shell/ShellLinkTests.cs @@ -0,0 +1,33 @@ +using NUnit.Framework; +using System; +using System.Runtime.InteropServices; +using System.Text; +using System.Windows.Forms; +using Vanara.InteropServices; +using Vanara.PInvoke; +using Vanara.PInvoke.Tests; +using static Vanara.PInvoke.Shell32; + +namespace Vanara.Windows.Shell.Tests +{ + [TestFixture] + public class ShellLinkTests + { + [Test] + public void UnsavedLinkTest() + { + using var lnk = new ShellLink(TestCaseSources.WordDoc, "/p", TestCaseSources.TempDir, "Test description"); + lnk.Title = "Test title"; + lnk.HotKey = Keys.Control | Keys.T; + lnk.RunAsAdministrator = false; + lnk.IconLocation = new IconLocation(TestCaseSources.ResourceFile, -107); + lnk.ShowState = FormWindowState.Minimized; + + var fn = System.IO.Path.GetTempFileName() + ".lnk"; + lnk.SaveAs(fn); + Assert.That(System.IO.File.Exists(fn), Is.True); + lnk.ViewInExplorer(); + System.IO.File.Delete(fn); + } + } +} \ No newline at end of file diff --git a/UnitTests/Windows.Shell/Windows.Shell.csproj b/UnitTests/Windows.Shell/Windows.Shell.csproj index f6ebf4e9..61251676 100644 --- a/UnitTests/Windows.Shell/Windows.Shell.csproj +++ b/UnitTests/Windows.Shell/Windows.Shell.csproj @@ -47,6 +47,7 @@ +