read handle from reg and show the window
This commit is contained in:
@@ -1138,6 +1138,12 @@ namespace v2rayN.Forms
|
|||||||
ShowInTaskbar = false;
|
ShowInTaskbar = false;
|
||||||
|
|
||||||
SetVisibleCore(false);
|
SetVisibleCore(false);
|
||||||
|
|
||||||
|
//write Handle to reg
|
||||||
|
if (IsHandleCreated)
|
||||||
|
{
|
||||||
|
Utils.RegWriteValue(Global.MyRegPath, Utils.WindowHwndKey, Convert.ToString((long)Handle));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using v2rayN.Forms;
|
using v2rayN.Forms;
|
||||||
using v2rayN.Properties;
|
|
||||||
using v2rayN.Tool;
|
using v2rayN.Tool;
|
||||||
|
|
||||||
namespace v2rayN
|
namespace v2rayN
|
||||||
{
|
{
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
|
||||||
private static extern bool SetProcessDPIAware();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 应用程序的主入口点。
|
/// 应用程序的主入口点。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -21,7 +16,7 @@ namespace v2rayN
|
|||||||
{
|
{
|
||||||
if (Environment.OSVersion.Version.Major >= 6)
|
if (Environment.OSVersion.Version.Major >= 6)
|
||||||
{
|
{
|
||||||
SetProcessDPIAware();
|
Utils.SetProcessDPIAware();
|
||||||
}
|
}
|
||||||
|
|
||||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||||
@@ -47,6 +42,22 @@ namespace v2rayN
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//read handle from reg and show the window
|
||||||
|
long.TryParse(Utils.RegReadValue(Global.MyRegPath, Utils.WindowHwndKey, ""), out long llong);
|
||||||
|
if (llong > 0)
|
||||||
|
{
|
||||||
|
var hwnd = (IntPtr)llong;
|
||||||
|
if (Utils.IsWindow(hwnd))
|
||||||
|
{
|
||||||
|
Utils.ShowWindow(hwnd, 4);
|
||||||
|
Utils.SwitchToThisWindow(hwnd, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
UI.ShowWarning($"v2rayN is already running(v2rayN已经运行)");
|
UI.ShowWarning($"v2rayN is already running(v2rayN已经运行)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ using System.Web;
|
|||||||
using log4net;
|
using log4net;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace v2rayN
|
namespace v2rayN
|
||||||
{
|
{
|
||||||
@@ -1111,5 +1112,30 @@ namespace v2rayN
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Windows API
|
||||||
|
|
||||||
|
public static string WindowHwndKey
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return $"WindowHwnd_{GetMD5(StartupPath())}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern bool SetProcessDPIAware();
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern int SwitchToThisWindow(IntPtr hwnd, bool fUnknown);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern bool IsWindow(IntPtr hwnd);
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user