mirror of https://github.com/dahall/Vanara.git
Added tests for ShellLink when not file-based and new TaskbarButton.
parent
ae3d4dc52c
commit
cb71434118
|
@ -49,10 +49,12 @@
|
||||||
this.themedPanel1 = new Vanara.Windows.Forms.ThemedPanel();
|
this.themedPanel1 = new Vanara.Windows.Forms.ThemedPanel();
|
||||||
this.themedImageDraw1 = new Vanara.Windows.Forms.ThemedImageDraw();
|
this.themedImageDraw1 = new Vanara.Windows.Forms.ThemedImageDraw();
|
||||||
this.ipAddressBox1 = new Vanara.Windows.Forms.IPAddressBox();
|
this.ipAddressBox1 = new Vanara.Windows.Forms.IPAddressBox();
|
||||||
|
this.taskbarButton1 = new Vanara.Windows.Shell.TaskbarButton(this.components);
|
||||||
this.groupBox1.SuspendLayout();
|
this.groupBox1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.trackBarEx1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.trackBarEx1)).BeginInit();
|
||||||
this.contextMenuStrip1.SuspendLayout();
|
this.contextMenuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.vistaControlExtender1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.vistaControlExtender1)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.taskbarButton1)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
|
@ -135,24 +137,24 @@
|
||||||
this.twoToolStripMenuItem,
|
this.twoToolStripMenuItem,
|
||||||
this.threeToolStripMenuItem});
|
this.threeToolStripMenuItem});
|
||||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||||
this.contextMenuStrip1.Size = new System.Drawing.Size(105, 70);
|
this.contextMenuStrip1.Size = new System.Drawing.Size(104, 70);
|
||||||
//
|
//
|
||||||
// oneToolStripMenuItem
|
// oneToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.oneToolStripMenuItem.Name = "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";
|
this.oneToolStripMenuItem.Text = "One";
|
||||||
//
|
//
|
||||||
// twoToolStripMenuItem
|
// twoToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.twoToolStripMenuItem.Name = "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";
|
this.twoToolStripMenuItem.Text = "Two";
|
||||||
//
|
//
|
||||||
// threeToolStripMenuItem
|
// threeToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.threeToolStripMenuItem.Name = "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";
|
this.threeToolStripMenuItem.Text = "Three";
|
||||||
//
|
//
|
||||||
// enumComboBox1
|
// 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.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.glassExtenderProvider1.SetGlassMargins(this, new System.Windows.Forms.Padding(0, 85, 0, 0));
|
||||||
this.Name = "Form1";
|
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);
|
this.groupBox1.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.trackBarEx1)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.trackBarEx1)).EndInit();
|
||||||
this.contextMenuStrip1.ResumeLayout(false);
|
this.contextMenuStrip1.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.vistaControlExtender1)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.vistaControlExtender1)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.taskbarButton1)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
|
@ -277,6 +282,7 @@
|
||||||
private Vanara.Windows.Forms.ThemedPanel themedPanel1;
|
private Vanara.Windows.Forms.ThemedPanel themedPanel1;
|
||||||
private Vanara.Windows.Forms.ThemedImageDraw themedImageDraw1;
|
private Vanara.Windows.Forms.ThemedImageDraw themedImageDraw1;
|
||||||
private Vanara.Windows.Forms.IPAddressBox ipAddressBox1;
|
private Vanara.Windows.Forms.IPAddressBox ipAddressBox1;
|
||||||
|
private Vanara.Windows.Shell.TaskbarButton taskbarButton1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Vanara.PInvoke;
|
||||||
|
using Vanara.Windows.Shell;
|
||||||
|
|
||||||
namespace Windows.Forms.App
|
namespace Windows.Forms.App
|
||||||
{
|
{
|
||||||
public partial class Form1 : Form
|
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 object currentDlg;
|
||||||
|
private List<string> tempFiles = new List<string>();
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
|
@ -16,7 +24,7 @@ namespace Windows.Forms.App
|
||||||
FillComboWithDialogs(dlgCombo);
|
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)
|
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);
|
currentDlg = dlgCombo.SelectedItem is null ? null : Activator.CreateInstance((Type)dlgCombo.SelectedItem);
|
||||||
propertyGrid1.SelectedObject = currentDlg;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -123,6 +123,9 @@
|
||||||
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>366, 17</value>
|
<value>366, 17</value>
|
||||||
</metadata>
|
</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" />
|
<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">
|
<data name="customButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
|
@ -173,4 +176,7 @@
|
||||||
ZnOqQcUYOEtLS2/wiY5P84GBgZdkTAzcmr9rHX1M8zEnawAAAABJRU5ErkJggg==
|
ZnOqQcUYOEtLS2/wiY5P84GBgZdkTAzcmr9rHX1M8zEnawAAAABJRU5ErkJggg==
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</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>
|
</root>
|
|
@ -81,6 +81,18 @@
|
||||||
<Project>{241f73ee-9298-45c9-b869-a045dff94c03}</Project>
|
<Project>{241f73ee-9298-45c9-b869-a045dff94c03}</Project>
|
||||||
<Name>Vanara.Core</Name>
|
<Name>Vanara.Core</Name>
|
||||||
</ProjectReference>
|
</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">
|
<ProjectReference Include="..\..\Windows.Forms\Vanara.Windows.Forms.csproj">
|
||||||
<Project>{51986cd3-eeda-4369-93a4-255512548f68}</Project>
|
<Project>{51986cd3-eeda-4369-93a4-255512548f68}</Project>
|
||||||
<Name>Vanara.Windows.Forms</Name>
|
<Name>Vanara.Windows.Forms</Name>
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,6 +47,7 @@
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="ShellLinkTests.cs" />
|
||||||
<Compile Include="ShellSearchTests.cs" />
|
<Compile Include="ShellSearchTests.cs" />
|
||||||
<Compile Include="ControlPanelTests.cs" />
|
<Compile Include="ControlPanelTests.cs" />
|
||||||
<Compile Include="ShellAssocTests.cs" />
|
<Compile Include="ShellAssocTests.cs" />
|
||||||
|
|
Loading…
Reference in New Issue