using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public class WindowMaxAndMin : MonoBehaviour
{
public static WindowMaxAndMin instance;
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", EntryPoint = "FindWindow")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr ParenthWnd = FindWindow(null, "BMYzhaopianqiang"); //build时候的项目名
const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}
const int SW_SHOWMAXIMIZED = 3;//最大化
const int SW_SHOWRESTORE = 1;//还原
private void Awake()
{
instance = this;
ParenthWnd = FindWindow(null, "BMYzhaopianqiang");
}
public void OnClickMinimize()
{ //最小化
//Debug.Log("GetForegroundWindow = " + GetForegroundWindow() + " ParenthWnd = " + ParenthWnd);
// ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED);
ShowWindow(ParenthWnd, SW_SHOWMINIMIZED);
//Invoke("OnClickMaximize", 5.0f) ;
}
public void OnClickMaximize()
{
//最大化
//ShowWindow(GetForegroundWindow(), SW_SHOWMAXIMIZED);
ShowWindow(ParenthWnd, SW_SHOWMAXIMIZED);
}
public void OnClickRestore()
{
//还原
ShowWindow(GetForegroundWindow(), SW_SHOWRESTORE);
}
}
“build时候的项目名”指的是:

|