Unity实现关闭应用程序和关闭应用窗口

embedded/2024/9/24 21:20:58/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using System;public class WindowsClose : MonoBehaviour
{// 声明需要使用的Windows API函数[DllImport("user32.dll", SetLastError = true)][return: MarshalAs(UnmanagedType.Bool)]static extern bool CloseWindow(IntPtr hWnd);//[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]//static extern IntPtr FindWindow(string lpClassName, string lpWindowName);// 调用CloseWindow函数关闭窗口 不触发 ondestory onapplicationquitpublic void CloseAppWindow(){// 获取当前窗口句柄IntPtr windowHandle = FindWindow(null, "WS Display Settings");// 关闭窗口if (windowHandle != IntPtr.Zero){CloseWindow(windowHandle);}}[DllImport("user32.dll", EntryPoint = "FindWindow")]private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);[DllImport("user32.dll", EntryPoint = "PostMessage", SetLastError = true)]public static extern bool PostMessage(IntPtr hwnd, uint Msg, uint wParam, uint lParam);public const int WM_SYSCOMMAND = 0x0112;public const int SC_CLOSE = 0xF060;/// <summary>/// 调用 PostMessage 函数关闭窗口  可触发 ondestory onapplicationquit/// </summary>public void CloseAppWindow1(){//IntPtr hwnd = FindWindow(null, "WsDisplaySettings");//PostMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);IntPtr hwnd1 = FindWindow(null, "WS Display Settings");PostMessage(hwnd1, WM_SYSCOMMAND, SC_CLOSE, 0);}}

http://www.ppmy.cn/embedded/9166.html

相关文章

Linux内核驱动开发-001字符设备开发-002led杂项驱动

1驱动程序 /*************************************************************************> File Name: led_misc.c> Author: yas> Mail: rage_yashotmail.com> Created Time: 2024年04月22日 星期一 16时20分42秒**********************************************…

【前端Vue】Vue3+Pinia小兔鲜电商项目第6篇:整体认识和路由配置,本资源由 收集整理【附代码文档】

Vue3ElementPlusPinia开发小兔鲜电商项目完整教程&#xff08;附代码资料&#xff09;主要内容讲述&#xff1a;认识Vue3&#xff0c;使用create-vue搭建Vue3项目1. Vue3组合式API体验,2. Vue3更多的优势,1. 认识create-vue,2. 使用create-vue创建项目,1. setup选项的写法和执行…

软件公司:饥一顿饱一顿,咋办?试一试外部柔性产能。

有人开玩笑&#xff0c;软件公司最理想状态就是&#xff1a;项目来了&#xff0c;公司有足够的人力消化产能&#xff1b;项目没了&#xff0c;人员都走了&#xff0c;不会造成产能搁置。 以上是个理想状态&#xff0c;事实上单纯依靠一个公司是做不到的&#xff0c;所以一定建立…

区块链实验室(35) - 编译solana for ARM64版

今天终于成功编译solana for arm64版&#xff0c;编译时间巨长。见下图所示。编译步骤详见solana网站https://github.com/solana-labs/solana和https://docs.solanalabs.com/。

http、https、json编程

文章目录 1、http编程2、https编程3、json编程 1、http编程 HTTP 编程 http&#xff0c;归属于应用层的超文本传输协议 状态码&#xff1a;2xx(没问题) 3xx(重定向问题) 4xx(客户端问题) 5xx(服务端问题) 请求格式&#xff1a; 请求行 举例&#xff1a;GET /index.html HTTP/1…

一文读懂链游!探索链游的前世今生,区块链与游戏结合的新兴趋势

区块链技术的崛起给游戏行业带来了前所未有的变革&#xff0c;而链游&#xff08;Blockchain Games&#xff09;正是这一变革的产物。本文将带您一览链游的前世今生&#xff0c;探索区块链与游戏结合的新兴趋势。 1. 链游的起源 链游&#xff0c;顾名思义&#xff0c;是指利用…

OpenHarmony开发案例:【电影卡片】

介绍 本篇Codelab基于元服务卡片的能力&#xff0c;实现带有卡片的电影应用&#xff0c;介绍卡片的开发过程和生命周期实现。需要完成以下功能&#xff1a; 元服务卡片&#xff0c;用于在桌面上添加2x2或2x4规格元服务卡片。关系型数据库&#xff0c;用于创建、查询、添加、删…

前端实用插件-日期处理工具Moment.js

安装和引入Moment.js 在开始使用Moment.js之前&#xff0c;我们需要将其引入到项目中。可以通过以下两种方式来安装和引入Moment.js&#xff1a; 使用CDN 在HTML文件的<head>标签中添加以下代码&#xff1a; <script src"https://cdn.jsdelivr.net/momentjs/…