using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.UI;
public class ShowWindow: MonoBehaviour
{
[DllImport("User32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
void FixedUpdate()
{
// 自己到进程去看软件名称
IntPtr name0= FindWindow(null, "appname");
if (name0== IntPtr.Zero)
{
return;
}
IntPtr activeWndHwnd = GetForegroundWindow();
// 如当前不是活动窗口,则改为活动窗口
if (hwnd != activeWndHwnd)
{
ShowWindowAsync(name0, 3);
SetForegroundWindow(name0);
}
}
}