添加不可重复启动软件限制
This commit is contained in:
parent
619794a192
commit
a5994c85a4
|
@ -6,7 +6,7 @@
|
|||
d1p1:Ignorable="d"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:local="clr-namespace:DM_Weight"
|
||||
xmlns:prism="http://prismlibrary.com/">
|
||||
xmlns:prism="http://prismlibrary.com/" Startup="PrismApplication_Startup">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
|
|
@ -24,6 +24,8 @@ using System.Windows.Interop;
|
|||
using System.Windows.Threading;
|
||||
using System.Timers;
|
||||
using DM_Weight.HIKVISION;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DM_Weight
|
||||
{
|
||||
|
@ -277,5 +279,42 @@ namespace DM_Weight
|
|||
logger.Info("结束APP-RegisterTypes");
|
||||
|
||||
}
|
||||
|
||||
private void PrismApplication_Startup(object sender, StartupEventArgs e)
|
||||
{
|
||||
//获取欲启动程序名
|
||||
string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
|
||||
//检查程序是否已经启动,已经启动则显示提示退出程序
|
||||
if (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1)
|
||||
{
|
||||
//系统在运行
|
||||
RaiseOtherProcess();
|
||||
Application.Current.Shutdown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
private static void RaiseOtherProcess()
|
||||
{
|
||||
Process proc = Process.GetCurrentProcess();
|
||||
foreach (Process otherProc in Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName))
|
||||
{
|
||||
if (proc.Id != otherProc.Id)
|
||||
{
|
||||
IntPtr hWnd = otherProc.MainWindowHandle;
|
||||
if (IsIconic(hWnd))
|
||||
{
|
||||
ShowWindowAsync(hWnd, 9);
|
||||
}
|
||||
SetForegroundWindow(hWnd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool IsIconic(IntPtr hWnd);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue