WindowMin.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Runtime.InteropServices;
  6. using UnityEngine;
  7. using WindowsHandler;
  8. public class WindowMin : MonoBehaviour
  9. {
  10. [DllImport("user32.dll")]
  11. public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
  12. [DllImport("user32.dll", EntryPoint = "FindWindow")]
  13. private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
  14. [DllImport("user32.dll")]
  15. static extern IntPtr GetForegroundWindow();
  16. // Start is called before the first frame update
  17. void Start()
  18. {
  19. Process[] pros=Process.GetProcesses();
  20. for (var i = 0; i < pros.Length; i++)
  21. {
  22. if(pros[i].ProcessName.Contains("Explore")||pros[i].ProcessName.Contains("explore")){
  23. pros[i].Kill();
  24. }
  25. }
  26. IReadOnlyList<WindowInfo> list=WindowEnumerator.FindAll();
  27. /* string mm="";
  28. Tools.WriteTxt(Application.streamingAssetsPath+"/2.txt",mm);
  29. for (int i = 0; i < list.Count; i++)
  30. {
  31. mm+="\n"+list[i].Title;
  32. UnityEngine.Debug.Log(list[i].Title);
  33. }
  34. Tools.WriteTxt(Application.streamingAssetsPath+"/2.txt",mm);*/
  35. string str = Tools.LoadString(Application.streamingAssetsPath + "/3.txt");
  36. //User32API.GetHandleByProcessName(str);
  37. IntPtr a=FindWindow(null,str);
  38. if(a!=IntPtr.Zero){
  39. Application.Quit();
  40. }
  41. ShowWindow(a, 2);
  42. ShowWindow(GetForegroundWindow(), 2);
  43. // StartCoroutine(AA());
  44. }
  45. IEnumerator AA(){
  46. yield return new WaitForSeconds(1);
  47. Application.Quit();
  48. }
  49. // Update is called once per frame
  50. void Update()
  51. {
  52. }
  53. }