A7:Unity窗口化无边框模式
将下面代码复制进入脚本里,然后随便放到一个物体上即可实现窗口化启动无边框哦~
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics;
using UnityEngine;
public class WindowMod : MonoBehaviour
{
///
/// 窗口宽度
///
private int winWidth;
///
/// 窗口高度
///
private int winHeight;
///
/// 窗口左上角x
///
private int winPosX;
///
/// 窗口左上角y
///
private int winPosY;
[DllImport(“user32.dll”)]
static extern IntPtr SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong);
[DllImport(“user32.dll”)]
static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport(“user32.dll”)]
static extern IntPtr GetForegroundWindow();
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
const int WS_POPUP = 0x800000;
///
/// 移除EXE的边框
///
void MoveEXEBound()
{
winWidth = 1280;
winHeight = 720;
//显示器支持的所有分辨率
int i = Screen.resolutions.Length;
int resWidth = Screen.resolutions[i - 1].width;int resHeight = Screen.resolutions[i - 1].height;winPosX = resWidth / 2 - winWidth / 2;winPosY = resHeight / 2 - winHeight / 2;SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_POPUP);bool result = SetWindowPos(GetForegroundWindow(), 0, winPosX, winPosY, winWidth, winHeight, SWP_SHOWWINDOW);
}
}
第二种方法: 动态设置有/无边框,最大化、最小化、鼠标拖动窗口
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using System;
using UnityEngine.EventSystems;
public class WindowsSetting : SingletonBase
{
//系统方法类实体
public WindowsTools winTool = new WindowsTools();//当前Unity程序进程
private static IntPtr currentWindow;
public void Start()
{
currentWindow = WindowsTools.GetForegroundWindow();
}
//最小化窗口
public void MinWindows()
{winTool.SetMinWindows();}//设置无边框窗口
public void SetNoFrame()
{//窗口大小 以此为例float windowWidth = 1280;float windowHeight = 720;//计算框体显示位置float posX = (Screen.currentResolution.width - windowWidth) / 2;float posY = (Screen.currentResolution.height - windowHeight) / 2;Rect _rect = new Rect(posX, posY, windowWidth, windowHeight);winTool.SetNoFrameWindow(_rect);
}/// <summary>
/// 全屏
/// </summary>
public void FullScreen()
{if (Screen.fullScreen){Screen.SetResolution(1024, 768, false);}else{Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, true);}//等待当前帧完成 再去除边框StartCoroutine(IE_NoFrame());
}private IEnumerator IE_NoFrame()
{yield return new WaitForEndOfFrame();yield return new WaitForFixedUpdate();if (!Screen.fullScreen){SetNoFrame();}
}//窗口拖动
public void Drag()
{winTool.DragWindow(currentWindow);
}
}
/* *
系统方法类
*/
public class WindowsTools
{//设置当前窗口的显示状态
[DllImport(“user32.dll”)]
public static extern bool ShowWindow(System.IntPtr hwnd, int nCmdShow);//获取当前激活窗口
[DllImport(“user32.dll”, EntryPoint = “GetForegroundWindow”)]
public static extern System.IntPtr GetForegroundWindow();//设置窗口边框
[DllImport(“user32.dll”)]
public static extern IntPtr SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong);//设置窗口位置,大小
[DllImport(“user32.dll”)]
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);//窗口拖动
[DllImport(“user32.dll”)]
public static extern bool ReleaseCapture();
[DllImport(“user32.dll”)]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);//边框参数
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
const int WS_POPUP = 0x800000;
const int SW_SHOWMINIMIZED = 2;//(最小化窗口)//最小化窗口
public void SetMinWindows()
{
ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED);
//具体窗口参数看这 https://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx
}//设置无边框,并设置框体大小,位置
public void SetNoFrameWindow(Rect rect)
{
SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_POPUP);
bool result = SetWindowPos(GetForegroundWindow(), 0, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height, SWP_SHOWWINDOW);
}//拖动窗口
public void DragWindow(IntPtr window)
{
ReleaseCapture();
SendMessage(window, 0xA1, 0x02, 0);
SendMessage(window, 0x0202, 0, 0);
}
}
/*xbb
拖动窗口UI
*/
public class WindowDragObject : MonoBehaviour, IPointerDownHandler, IPointerExitHandler, IPointerUpHandler
{
private bool isDrag = false;void Update()
{
if (isDrag == true)
{
WindowsSetting.Instance.Drag();
}
}public void OnPointerExit(PointerEventData eventData)
{
isDrag = false;
}public void OnPointerUp(PointerEventData eventData)
{
isDrag = false;
}public void OnPointerDown(PointerEventData eventData)
{
isDrag = true;
}
}
A7:Unity窗口化无边框模式相关推荐
- 无边框模式对话框,设置鼠标拖动
无边框模式对话框,设置鼠标拖动 1. 对话框中创建成员变量 long _icur; 2. 响应对话框类消息 WM_NCHITTEST ScreenToClient(&point); RECT ...
- 让对话框不显示边框_微信消息“无边框”模式搭配这款壁纸,简直绝了
技能:好运壁纸,微信"无边框"聊天背景图 难度系数:1颗星 适用系统:安卓,iOS(苹果) 今天所长想给大家介绍一组会让人好运爆棚的壁纸,不过,运营妹纸给我分享了一款有趣的聊天背景 ...
- C# WinForm 无边框窗体,加阴影、拖动、改变大小等功能完美实现(自认为是完美的 ^=^)
关于Winform的无边框窗体实现,网络上有很多大牛文章,这里不赘述.我也是参考网络上的思路,在使用别人的代码基础上,发现和遇到了很多小问题,所以做了改造,以下做个记录,也是给需要的人提供一点思路,如 ...
- PotPlayer:最强播放器,无边框
下载地址: 链接:https://pan.baidu.com/s/1QnuCm1OTOJompZJDuF2gFg 提取码:3elw 1.无边框+简约皮肤 如果有人问这款播放器的优点有哪些? 很多人可能 ...
- 小米MIX Alpha获得百万美金技术大奖;索尼或将推出无边框手机;Linus 不建议用 ZFS | 极客头条...
整理 | 屠敏 快来收听极客头条音频版吧,智能播报由标贝科技提供技术支持. 「极客头条」-- 技术人员的新闻圈! CSDN 的读者朋友们早上好哇,「极客头条」来啦,快来看今天都有哪些值得我们技术人关注 ...
- Win10《芒果TV》更新v3.8.30流星版:优化稳定性、升级无边框播放体验
随着暑假到来,大波王牌综艺和青春电视剧热浪来袭,Win10版<芒果TV>全平台同步更新流星版v3.8.30,进一步提升稳定性,巩固播放体验,升级剧场模式和画中画无边框体验,我们在芒果等你. ...
- 犀牛软件无边框编辑设计,提高模型中的工作速度
犀牛软件无边框编辑设计,提高模型中的工作速度 犀牛是设计专业设计师的软件工程师之一,允许用户设计问题,因为他们做不同类型的模型.在犀牛中建立等级的原则是建立边缘.为了在犀牛环境中建模,在空间中创建一个 ...
- 无边框窗体和用户控件以及权限
无边框窗体: 就是吧窗体的边框去掉,然后自己做按钮设置功能. 无边框窗体的移动: 将下面代码直接复制粘贴,将窗体的鼠标按下事件的方法改成下面方法的名字就可以直接使用 1 //窗体移动API 2 [Dl ...
- 爬虫之selenium开启无界面模式
绝大多数服务器是没有界面的,selenium控制谷歌浏览器也是存在无界面模式的(又称之为无头模式) 开启无界面模式的方法 实例化配置对象 options = webdriver.ChromeOptio ...
最新文章
- Android选项卡置底的方法
- Redis中RedisTemplate和Redisson管道的使用
- MapReduce源码分析之作业Job状态机解析(一)简介与正常流程浅析
- MySQL注入中报错的利用
- 前端工程化:围绕Jenkins打造工作流的过程
- ipad无法充电怎么办_IPAD充电线破损无法保修,资深“果粉”吐槽:店大欺客!...
- 痛心!Pandownload开发者被抓!我终于决定使用Docker搭建一个多端同步网盘!
- 【Java】使用Switch语句实现成绩等级判断
- webpack-dev-server启动后, localhost:8080返回index.html的原理
- 基于数据驱动的人脸识别课题研究
- hadoop3.3.0集群搭建(详细教程)
- 做工作必须将心比心——感谢译者陈浩对我们的批评
- C# WebSocket(Fleck) 客户端:html Winfrom
- html+angularjs+redis获取后台数据模拟京东/天猫的商品分类导航
- 长安沦陷国家破碎,只有山河依旧,
- ubuntu14.04使用reaver跑pin码
- swoole的初步学习
- 系统集成16真题解析
- 中文词性标注的简单实现
- 复变函数及应用 第二章学习感受
热门文章
- 异常(Exception)与错误(Error)
- 5G商用牌照将于今日发放;华为联手苏宁做电视;微软甲骨文整合云计算 | 雷锋早报
- 与OA系统的固定资产管理相比,固定资产管理云系统的优势在哪里?
- CF 739E Gosha is Hunting
- 博应用软件对小米路由器4C配置详细介绍
- matlab图片白边_MATLAB 保存的图片有白边如何解决
- 使用Git命令-查看远程分支、本地分支、创建分支、删除分支的方法
- [转] invariance(不变性)解释与图例
- 【笔记】从0开发浏览器上的语音聊天室系统
- SQL增加、修改、删除数据