123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using UnityEngine;
- using WindowsHandler;
- public class WindowMaxAndMin : MonoBehaviour
- {
- [DllImport("user32.dll")]
- public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
- [DllImport("user32.dll")]
- static extern IntPtr GetForegroundWindow();
- // 查找窗口句柄
- [DllImport("user32.dll")]
- static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}
- const int SW_SHOWMAXIMIZED = 3;//最大化
- const int SW_SHOWRESTORE = 1;//还原
- Process[] pros;
- private void Start()
- {
-
- // OnClickMinimize();
-
- }
- IEnumerator AA()
- {
- yield return new WaitForSeconds(5);
-
- }
- [ContextMenu("111")]
- public void OnClickMinimize()
- {
- var windows = WindowEnumerator.FindAll(_ => true);
- for (int i = 0; i < windows.Count; i++)
- {
- var window = windows[i];
- if (window.Title.Contains("o"))
- UnityEngine.Debug.Log($@"{i.ToString().PadLeft(3, ' ')}. {window.Title}
- {window.Bounds.X}, {window.Bounds.Y}, {window.Bounds.Width}, {window.Bounds.Height}");
- }
- IntPtr handle = FindWindow(null, "Goole_Chrome");
- if (handle == IntPtr.Zero)
- {
- UnityEngine.Debug.Log(1);
- }
- else
- {
- UnityEngine.Debug.Log(2);
- return;
- }
- //最小化
- // ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED);
- }
- public void OnClickMaximize()
- {
- //最大化
- ShowWindow(GetForegroundWindow(), SW_SHOWMAXIMIZED);
- }
- public void OnClickRestore()
- {
- //还原
- ShowWindow(GetForegroundWindow(), SW_SHOWRESTORE);
- }
- }
|