考虑:
public partial class App : Application
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private Mutex myMutex;
protected override void OnStartup(StartupEventArgs theArgs)
{
bool aIsNewInstance = false;
myMutex = new Mutex(true, "Testing", out aIsNewInstance);
if (!aIsNewInstance)
{
App.Current.Shutdown();
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
IntPtr pointer = FindWindow(null, "Testing");
App.Current.Shutdown();
ShowWindow(pointer, 1);
break;
}
}
}
当我双击图标时,如何阻止启动应用程序的第二个副本,而是让已经运行且最小化的托盘应用程序显示窗口?
答案 0 :(得分:0)