设置启动机制,等待测试
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
<Application x:Class="软件系统服务端Wpf.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:软件系统服务端Wpf"
|
||||
StartupUri="MainWindow.xaml">
|
||||
xmlns:local="clr-namespace:软件系统服务端Wpf">
|
||||
<Application.Resources>
|
||||
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
|
||||
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
@@ -13,9 +16,66 @@ namespace 软件系统服务端Wpf
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// 指示了应用程序退出时的代码
|
||||
/// </summary>
|
||||
public static int QuitCode { get; set; } = 0;
|
||||
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
//捕获未处理的异常
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
|
||||
Process process = Process.GetCurrentProcess();
|
||||
//遍历应用程序的同名进程组
|
||||
foreach (Process p in Process.GetProcessesByName(process.ProcessName))
|
||||
{
|
||||
//不是同一进程则关闭刚刚创建的进程
|
||||
if (p.Id != process.Id)
|
||||
{
|
||||
//此处显示原先的窗口需要一定的时间,不然无法显示
|
||||
ShowWindowAsync(p.MainWindowHandle, 9);
|
||||
SetForegroundWindow(p.MainWindowHandle);
|
||||
Thread.Sleep(10);
|
||||
Current.Shutdown();//关闭当前的应用程序
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
P1:
|
||||
|
||||
LoginWindow lw = new LoginWindow();
|
||||
if (lw.ShowDialog().Value == true)
|
||||
{
|
||||
MainWindow mw=new MainWindow();
|
||||
MainWindow = mw;
|
||||
mw.ShowDialog();
|
||||
if (QuitCode == 1)
|
||||
{
|
||||
//继续显示登录窗口
|
||||
QuitCode = 0;
|
||||
goto P1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
private static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,27 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:软件系统服务端Wpf"
|
||||
mc:Ignorable="d"
|
||||
Title="LoginWindow" Height="300" Width="500">
|
||||
Title="LoginWindow" Height="300" Width="500" WindowStartupLocation="CenterScreen">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.CheckBox.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ListBox.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.RadioButton.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
|
||||
<StackPanel>
|
||||
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Margin="0 12 8 0" Width="100"
|
||||
ToolTip="随便测试下" Click="Button_Click">
|
||||
点击进入
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -23,5 +23,10 @@ namespace 软件系统服务端Wpf
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.DialogResult = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user