WPF 防止程序多开


 

 

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
[DllImport("user32")]
private static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

protected override void OnStartup(StartupEventArgs e)
{
IntPtr parenthWnd = FindWindow(null, Assembly.GetExecutingAssembly().GetName().Name);
if (parenthWnd != IntPtr.Zero)
{
//选中当前的句柄窗口
SetForegroundWindow(parenthWnd);
Application.Current.Shutdown();
return;
}
base.OnStartup(e);
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM