Added tests for ShellLink when not file-based and new TaskbarButton.

pull/119/head
dahall 2020-02-26 15:21:21 -07:00
parent ae3d4dc52c
commit cb71434118
6 changed files with 102 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -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<string> tempFiles = new List<string>();
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);
}
}
}
}

View File

@ -123,6 +123,9 @@
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>366, 17</value>
</metadata>
<metadata name="vistaControlExtender1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="customButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
@ -173,4 +176,7 @@
ZnOqQcUYOEtLS2/wiY5P84GBgZdkTAzcmr9rHX1M8zEnawAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="taskbarButton1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>521, 17</value>
</metadata>
</root>

View File

@ -81,6 +81,18 @@
<Project>{241f73ee-9298-45c9-b869-a045dff94c03}</Project>
<Name>Vanara.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\PInvoke\Shared\Vanara.PInvoke.Shared.csproj">
<Project>{a5e519e9-feba-4fe3-93a5-b8269bef72f4}</Project>
<Name>Vanara.PInvoke.Shared</Name>
</ProjectReference>
<ProjectReference Include="..\..\PInvoke\Shell32\Vanara.PInvoke.Shell32.csproj">
<Project>{3226020f-4c9d-41b3-ac8a-2bc9fd064cd8}</Project>
<Name>Vanara.PInvoke.Shell32</Name>
</ProjectReference>
<ProjectReference Include="..\..\PInvoke\ShlwApi\Vanara.PInvoke.ShlwApi.csproj">
<Project>{30FD6779-6549-449E-880A-695815EB89B0}</Project>
<Name>Vanara.PInvoke.ShlwApi</Name>
</ProjectReference>
<ProjectReference Include="..\..\Windows.Forms\Vanara.Windows.Forms.csproj">
<Project>{51986cd3-eeda-4369-93a4-255512548f68}</Project>
<Name>Vanara.Windows.Forms</Name>

View File

@ -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);
}
}
}

View File

@ -47,6 +47,7 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="ShellLinkTests.cs" />
<Compile Include="ShellSearchTests.cs" />
<Compile Include="ControlPanelTests.cs" />
<Compile Include="ShellAssocTests.cs" />