关于隔热型材加工那些事儿
2026/7/21 9:26:54
版本:6000.3.19f1
using System; using System.Runtime.InteropServices; using UnityEngine; [RequireComponent(typeof(Camera))] public class WindowsStyle : MonoBehaviour { /// <summary> 最小化 </summary> private const int SW_SHOWMINIMIZED = 2; /// <summary> 最大化 </summary> private const int SW_SHOWMAXIMIZED = 3; /// <summary> 还原 </summary> private const int SW_SHOWRESTORE = 1; /// <summary> 窗口风格 </summary> private const int GWL_STYLE = -16; /// <summary> 标题栏 </summary> private const int WS_CAPTION = 0x00c00000; /// <summary> 标题栏按钮 </summary> private const int WS_SYSMENU = 0x00080000; [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hwd, int cmdShow); [DllImport("user32.dll")] public static extern long GetWindowLong(IntPtr hwd, int nIndex); [DllImport("user32.dll")] public static extern void SetWindowLong(IntPtr hwd, int nIndex, long dwNewLong); private bool closeWindow; private void Awake() { // 关闭按钮执行最小化 Application.wantsToQuit += () => { // 获得窗口句柄 IntPtr hwd = GetForegroundWindow(); // 设置窗口最小化 ShowWindow(hwd, SW_SHOWMINIMIZED); // 阻止程序被关闭 return closeWindow; }; } private void OnGUI() { if (GUILayout.Button("隐藏标题栏")) Listener_HideBar(); if (GUILayout.Button("显示标题栏")) Listener_ShowBar(); if (GUILayout.Button("隐藏关闭按钮")) Listener_HideCloseBtn(); if (GUILayout.Button("显示关闭按钮")) Listener_ShowCloseBtn(); if (GUILayout.Button("窗口最大化")) Listener_ShowMaxWindow(); if (GUILayout.Button("窗口还原化")) Listener_ShowRestoreWindow(); closeWindow = GUILayout.Toggle(closeWindow, "关闭窗口"); } private void Listener_HideBar() { // 获得窗口句柄 IntPtr hwd = GetForegroundWindow(); long wl = GetWindowLong(hwd, GWL_STYLE); wl &= ~WS_CAPTION; SetWindowLong(hwd, GWL_STYLE, wl); } private void Listener_ShowBar() { // 获得窗口句柄 IntPtr hwd = GetForegroundWindow(); long wl = GetWindowLong(hwd, GWL_STYLE); wl |= WS_CAPTION; SetWindowLong(hwd, GWL_STYLE, wl); } private void Listener_HideCloseBtn() { // 获得窗口句柄 IntPtr hwd = GetForegroundWindow(); long wl = GetWindowLong(hwd, GWL_STYLE); wl &= ~WS_SYSMENU; SetWindowLong(hwd, GWL_STYLE, wl); } private void Listener_ShowCloseBtn() { // 获得窗口句柄 IntPtr hwd = GetForegroundWindow(); long wl = GetWindowLong(hwd, GWL_STYLE); wl |= WS_SYSMENU; SetWindowLong(hwd, GWL_STYLE, wl); } private void Listener_ShowMaxWindow() { // 获得窗口句柄 IntPtr hwd = GetForegroundWindow(); // 设置窗口最大化 ShowWindow(hwd, SW_SHOWMAXIMIZED); } private void Listener_ShowRestoreWindow() { // 获得窗口句柄 IntPtr hwd = GetForegroundWindow(); // 设置窗口还原化 ShowWindow(hwd, SW_SHOWRESTORE); } }using System; using System.Runtime.InteropServices; using UnityEngine; using UnityEngine.Events; public class WindowsMessageBox : MonoBehaviour { /// <summary> /// 弹窗 /// </summary> /// <param name="handle">默认为IntPtr.Zero</param> /// <param name="message">消息框内容</param> /// <param name="title">消息框标题</param> /// <param name="type">消息框样式:<br/>①确定按钮:_MB_OK=@0x0;<br/>②确定、取消按钮:_MB_OKCANCEL=@0x1;<br/>③终止、重试、忽略按钮:_MB_ABORTRETRYIGNORE=@0x2;<br/>④是、否、取消按钮:_MB_YESNOCANCEL=@0x3;<br/>⑤是、否按钮:_MB_YESNO=@0x4;<br/>⑥重试取消按钮:_MB_RETRYCANCEL=@0x5;<br/>⑦终止、重试、继续 0x00000006(需声明API才能使用)</param> /// <returns>1 = 确定按钮:IDOK;<br/>2 = 取消按钮:IDCANCEL;<br/>3 = 终止按钮:IDABORT;<br/>4 = 重试按钮:IDRETRY;<br/>5 = 忽略按钮:IDIGNORE;<br/>6 = 是按钮:IDYES;<br/>7 = 否按钮:IDNO</returns> [DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] public static extern int MessageBox(IntPtr handle, String message, String title, int type);//具体方法 /// <summary> /// 消息框内容 /// </summary> /// <param name="message">消息框内容</param> /// <param name="type">消息框样式:<br/>①确定按钮:_MB_OK=@0x0;<br/>②确定、取消按钮:_MB_OKCANCEL=@0x1;<br/>③终止、重试、忽略按钮:_MB_ABORTRETRYIGNORE=@0x2;<br/>④是、否、取消按钮:_MB_YESNOCANCEL=@0x3;<br/>⑤是、否按钮:_MB_YESNO=@0x4;<br/>⑥重试取消按钮:_MB_RETRYCANCEL=@0x5;<br/>⑦终止、重试、继续 0x00000006(需声明API才能使用)</param> /// <param name="okAction"></param> /// <param name="cancleAction"></param> /// <param name="abortAction"></param> /// <param name="retryAction"></param> /// <param name="ignoreAction"></param> /// <param name="yesAction"></param> /// <param name="noAction"></param> /// <param name="title">消息框标题</param> public static void MessageBox(string message, int type, UnityAction okAction = null, UnityAction cancleAction = null, UnityAction abortAction = null, UnityAction retryAction = null, UnityAction ignoreAction = null, UnityAction yesAction = null, UnityAction noAction = null, string title = "提示") { int messageIndex = MessageBox(IntPtr.Zero, message, title, type); switch (messageIndex) { case 1: okAction?.Invoke(); break; case 2: cancleAction?.Invoke(); break; case 3: abortAction?.Invoke(); break; case 4: retryAction?.Invoke(); break; case 5: ignoreAction?.Invoke(); break; case 6: yesAction?.Invoke(); break; case 7: noAction?.Invoke(); break; } } }