refactoring singleinstance
+pass parameter to active singleinstance
This commit is contained in:
parent
3c62f0bd9e
commit
e1ed357709
|
@ -472,8 +472,9 @@
|
||||||
this.MinimumSize = new System.Drawing.Size(983, 605);
|
this.MinimumSize = new System.Drawing.Size(983, 605);
|
||||||
this.Name = "Main";
|
this.Name = "Main";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "Image Sorter v1.27 | © 2015-2019 by manuelkamper.com";
|
this.Text = "Image Sorter v1.28 | © 2015-2019 by manuelkamper.com";
|
||||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing);
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing);
|
||||||
|
this.Load += new System.EventHandler(this.Main_Load);
|
||||||
this.Shown += new System.EventHandler(this.Main_Shown);
|
this.Shown += new System.EventHandler(this.Main_Shown);
|
||||||
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Main_KeyDown);
|
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Main_KeyDown);
|
||||||
this.Resize += new System.EventHandler(this.Main_ResizeEnd);
|
this.Resize += new System.EventHandler(this.Main_ResizeEnd);
|
||||||
|
|
|
@ -6,7 +6,6 @@ using Mk0.Tools.Randomization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
|
@ -41,21 +40,48 @@ namespace Mk0.Software.ImageSorter
|
||||||
private string zoomType = "auto";
|
private string zoomType = "auto";
|
||||||
private string startuppath;
|
private string startuppath;
|
||||||
private string startupimage;
|
private string startupimage;
|
||||||
|
public string[] Args;
|
||||||
|
|
||||||
public Main(string startuppath)
|
public Main()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
banner = new Banner(components, panel3, pictureBox1, pictureBox2, label1, label2);
|
banner = new Banner(components, panel3, pictureBox1, pictureBox2, label1, label2);
|
||||||
pictureBox.Cursor = grabCursor;
|
pictureBox.Cursor = grabCursor;
|
||||||
DoubleBuffered = true;
|
DoubleBuffered = true;
|
||||||
if (!string.IsNullOrEmpty(startuppath) && File.Exists(startuppath))
|
|
||||||
{
|
|
||||||
this.startuppath = Path.GetDirectoryName(startuppath);
|
|
||||||
startupimage = Path.GetFileName(startuppath);
|
|
||||||
}
|
|
||||||
SetDefaultPath();
|
SetDefaultPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Main_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (Args != null)
|
||||||
|
{
|
||||||
|
ProcessParameters(null, Args);
|
||||||
|
Args = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void ProcessParametersDelegate(object sender, string[] args);
|
||||||
|
public void ProcessParameters(object sender, string[] args)
|
||||||
|
{
|
||||||
|
if (args != null && args.Length != 0)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(args[0]) && File.Exists(args[0]))
|
||||||
|
{
|
||||||
|
startuppath = Path.GetDirectoryName(args[0]);
|
||||||
|
startupimage = Path.GetFileName(args[0]);
|
||||||
|
if (!string.IsNullOrEmpty(startuppath) && File.Exists(startuppath))
|
||||||
|
{
|
||||||
|
startuppath = Path.GetDirectoryName(startuppath);
|
||||||
|
startupimage = Path.GetFileName(startuppath);
|
||||||
|
}
|
||||||
|
SetDefaultPath();
|
||||||
|
SearchImages();
|
||||||
|
CountPicsInPath();
|
||||||
|
LoadPicture(GetImageIndex(Path.Combine(startuppath, startupimage)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default: Lädt das erste Bild
|
/// Default: Lädt das erste Bild
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -95,10 +95,6 @@
|
||||||
<HintPath>..\Mk0.Tools.Randomization.dll</HintPath>
|
<HintPath>..\Mk0.Tools.Randomization.dll</HintPath>
|
||||||
<EmbedInteropTypes>False</EmbedInteropTypes>
|
<EmbedInteropTypes>False</EmbedInteropTypes>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Mk0.Tools.SingleInstance">
|
|
||||||
<HintPath>..\Mk0.Tools.SingleInstance.dll</HintPath>
|
|
||||||
<EmbedInteropTypes>False</EmbedInteropTypes>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
@ -175,7 +171,6 @@
|
||||||
<Content Include="dll\Mk0.Tools.ImageCropper.dll" />
|
<Content Include="dll\Mk0.Tools.ImageCropper.dll" />
|
||||||
<Content Include="dll\Mk0.Tools.Images.dll" />
|
<Content Include="dll\Mk0.Tools.Images.dll" />
|
||||||
<Content Include="dll\Mk0.Tools.Randomization.dll" />
|
<Content Include="dll\Mk0.Tools.Randomization.dll" />
|
||||||
<Content Include="dll\Mk0.Tools.SingleInstance.dll" />
|
|
||||||
<Content Include="Resources\bmp.ico" />
|
<Content Include="Resources\bmp.ico" />
|
||||||
<Content Include="Resources\gif.ico" />
|
<Content Include="Resources\gif.ico" />
|
||||||
<Content Include="image.ico" />
|
<Content Include="image.ico" />
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using Microsoft.VisualBasic.ApplicationServices;
|
||||||
using Mk0.Tools.SingleInstance;
|
|
||||||
|
|
||||||
namespace Mk0.Software.ImageSorter
|
namespace Mk0.Software.ImageSorter
|
||||||
{
|
{
|
||||||
|
@ -12,9 +11,39 @@ namespace Mk0.Software.ImageSorter
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
App myApp = new App();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
myApp.Run(args);
|
||||||
SingleApplication.Run(args.Length == 0 ? new Main(string.Empty) : new Main(args[0]), Properties.Settings.Default.singleInstance);
|
}
|
||||||
|
|
||||||
|
class App : WindowsFormsApplicationBase
|
||||||
|
{
|
||||||
|
public App()
|
||||||
|
{
|
||||||
|
IsSingleInstance = Properties.Settings.Default.singleInstance;
|
||||||
|
EnableVisualStyles = true;
|
||||||
|
|
||||||
|
ShutdownStyle = ShutdownMode.AfterMainFormCloses;
|
||||||
|
StartupNextInstance += new StartupNextInstanceEventHandler(SIApp_StartupNextInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnCreateMainForm()
|
||||||
|
{
|
||||||
|
MainForm = new Main();
|
||||||
|
((Main)MainForm).Args = new string[CommandLineArgs.Count];
|
||||||
|
CommandLineArgs.CopyTo(((Main)MainForm).Args, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void SIApp_StartupNextInstance(object sender, StartupNextInstanceEventArgs eventArgs)
|
||||||
|
{
|
||||||
|
string[] args = new string[eventArgs.CommandLine.Count];
|
||||||
|
eventArgs.CommandLine.CopyTo(args, 0);
|
||||||
|
|
||||||
|
object[] parameters = new object[2];
|
||||||
|
parameters[0] = MainForm;
|
||||||
|
parameters[1] = args;
|
||||||
|
|
||||||
|
MainForm.Invoke(new Main.ProcessParametersDelegate(((Main)MainForm).ProcessParameters), parameters);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||||
// übernehmen, indem Sie "*" eingeben:
|
// übernehmen, indem Sie "*" eingeben:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.27.*")]
|
[assembly: AssemblyVersion("1.28.*")]
|
||||||
//[assembly: AssemblyFileVersion("1.6.0.0")]
|
//[assembly: AssemblyFileVersion("1.6.0.0")]
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue