76 lines
2.7 KiB
C#
76 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
using static UnityEngine.Rendering.VirtualTexturing.Debugging;
|
|
|
|
public class windowReset : MonoBehaviour
|
|
{
|
|
public static windowReset Instance;
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
private static extern int GetSystemMetrics(int nIndex);
|
|
private static int SM_CXSCREEN = 0; //主屏幕分辨率宽度
|
|
private static int SM_CYSCREEN = 1; //主屏幕分辨率高度
|
|
private static int SM_CYCAPTION = 4; //标题栏高度
|
|
private static int SM_CXFULLSCREEN = 16; //最大化窗口宽度(减去任务栏)
|
|
private static int SM_CYFULLSCREEN = 17; //最大化窗口高度(减去任务栏)
|
|
|
|
//当前Unity程序进程
|
|
private static IntPtr currentWindow;
|
|
public WindowsTools winTool = new WindowsTools();
|
|
|
|
|
|
|
|
public delegate bool EnumThreadWindowsCallback(IntPtr hWnd, IntPtr lParam);
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);
|
|
|
|
// 声明FindWindow函数
|
|
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
|
|
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
// 屏幕分辨率
|
|
int x = GetSystemMetrics(SM_CXSCREEN);
|
|
int y = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
// 屏幕WorkingArea
|
|
int x1 = GetSystemMetrics(SM_CXFULLSCREEN);
|
|
int y1 = GetSystemMetrics(SM_CYFULLSCREEN);
|
|
|
|
// 标题栏高度
|
|
int title = GetSystemMetrics(SM_CYCAPTION);
|
|
|
|
// 不最大化、不全屏的最大窗口高度
|
|
int maxHeight = y1 - title;
|
|
|
|
UnityEngine.Debug.Log(AppDomain.CurrentDomain.BaseDirectory + "\\ToolsForm");
|
|
UnityEngine.Debug.Log("屏幕分辨率" + x.ToString() + y.ToString());
|
|
UnityEngine.Debug.Log("屏幕workingArea" + x1.ToString() + y1.ToString());
|
|
UnityEngine.Debug.Log("标题栏高度" + title.ToString());
|
|
UnityEngine.Debug.Log("不最大化、不全屏的最大窗口高度" + maxHeight.ToString());
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
DontDestroyOnLoad(gameObject);
|
|
//设置初始窗口高和宽
|
|
|
|
//currentWindow = WindowsTools.GetForegroundWindow();
|
|
currentWindow = FindWindow(null, "ict_component");
|
|
winTool.old(currentWindow);
|
|
UnityEngine.Debug.Log("窗口设置成功");
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|