Unity exe去掉边框

来源:互联网 发布:c 数据采集系统源代码 编辑:程序博客网 时间:2024/06/05 05:26

有时用unity发布exe,但是不希望有系统自带的那个最小化,关闭的的边框,下面就来了:

using System;using System.Collections;using System.Collections.Generic;using System.Runtime.InteropServices;using UnityEngine;public class WindowRemoveBorder : MonoBehaviour {    public Rect screenPosition;    [DllImport("user32.dll")]    static extern IntPtr SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong);    [DllImport("user32.dll")]    static extern bool SetWindowPos(IntPtr hWnd, int hWndInserAfter, int X, int Y, int cx, int cy, uint uFlags);    [DllImport("user32.dll")]    static extern IntPtr GetForegroundWindow();    [DllImport("User32.dll", EntryPoint = "GetSystemMetrics")]    public static extern IntPtr GetSystemMetrics(int nIndex);    const int SM_CXSCREEN = 0x00000000;    const int SM_CYSCREEN = 0x00000001;      const uint SWP_SHOWWINDOW = 0x0040;    const int GWL_STYLE = -16;    const int WS_BORDER = 1;    const int WS_POPUP = 0x800000;    void Start()    {        //当前屏幕分辨率          int resWidth = (int)GetSystemMetrics(SM_CXSCREEN);          int resHeight = (int)GetSystemMetrics(SM_CYSCREEN);        //窗体的宽高        screenPosition.width = Screen.width;        screenPosition.height = Screen.height;        //设置窗体的位置        screenPosition.x = resWidth / 2 - screenPosition.width / 2;        screenPosition.y = resHeight / 2 - screenPosition.height / 2;        //将网上的WS_BORDER替换成WS_POPUP        SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_POPUP);        bool result = SetWindowPos(GetForegroundWindow(), 0, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);    }}

效果图



参考文章:

1、http://www.360doc.com/content/16/0620/14/30388632_569261323.shtml

2、http://blog.csdn.net/awnuxcvbn/article/details/38545419

原创粉丝点击