using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
//using UnityEngine.SceneManagement;
using System;
using UnityEngine.UI;
using System.Runtime.InteropServices; public class DrawWindow : MonoBehaviour
{     //private GameObject go;
    private 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 hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    [DllImport("user32.dll")]
    static extern IntPtr GetForegroundWindow();     [DllImport("user32.dll")]
    public static extern bool ReleaseCapture();
    [DllImport("user32.dll")]
    public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);     [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);     /// <summary>  
    /// 窗口宽度  
    /// </summary>  
    public int winWidth;
    /// <summary>  
    /// 窗口高度  
    /// </summary>  
    public int winHeight;
    /// <summary>  
    /// 窗口左上角x  
    /// </summary>  
    public int winPosX;
    /// <summary>  
    /// 窗口左上角y  
    /// </summary>  
    public int winPosY;     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; //{最小化, 激活}
    const int SW_SHOWMAXIMIZED = 3; //{最大化, 激活}      public void btn_onclick()
    { //最小化 
        ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED);
    }
    public void btn_onclickxx()
    { //最大化
        ShowWindow(GetForegroundWindow(), SW_SHOWMAXIMIZED);     }
    public void btn_onclickxxx()
    {//窗口化
        Screen.fullScreen = false;
        Screen.SetResolution(900, 540, false);
    }     public void btn_onclickxxxx()
    {//默认分辨率无边框显示(可以自由根据winWidth和winHeight的值调整无边框的分辨率)
        
        winWidth = 900;
        winHeight = 540;
        //显示器支持的所有分辨率  
        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);
    }     public void btn_onclickxxxxx()
    {//第二分辨率显示
        Resolution[] resolutions = Screen.resolutions;
        int i = resolutions.Length;
        winWidth = resolutions[i - 2].width;
        winHeight = resolutions[i-2].height;         //
                 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);
    }     IntPtr Handle;
    bool bx;     bool isMainScene = false;     void Awake()
    {
        bx = false;
#if UNITY_STANDALONE_WIN
        Resolution[] r = Screen.resolutions;
        screenPosition = new Rect((r[r.Length - 1].width - Screen.width) / 2, (r[r.Length - 1].height - Screen.height) / 2, Screen.width, Screen.height);         SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_POPUP);//将网上的WS_BORDER替换成WS_POPUP  
        Handle = GetForegroundWindow();   //FindWindow ((string)null, "popu_windows");
        SetWindowPos(GetForegroundWindow(), 0, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);
#endif
        btn_onclickxxxxx();         //go = transform.Find("go").gameObject;
        //DontDestroyOnLoad(go);
    }     void Update()
    {         MyDrag();
//测试各个分辨率的按键。
        if (Input.GetKey(KeyCode.A))
        {
            btn_onclickxxxxx();
        }
        if (Input.GetKey(KeyCode.Escape))
        {
            btn_onclick();
        }
        if (Input.GetKey(KeyCode.W))
        {
            btn_onclickxx();
        }
        if (Input.GetKey(KeyCode.Q))
        {
            btn_onclickxxxx();
        }
    }     /// <summary>
    /// 自定义的只能在某些区域内点击有效的拖拽
    /// </summary>
    private void MyDrag()
    {
        if (bx)
        { //这样做为了区分界面上面其它需要滑动的操作
            ReleaseCapture();
            SendMessage(Handle, 0xA1, 0x02, 0);
            SendMessage(Handle, 0x0202, 0, 0);
        }
    }     public void OnPointerEnter(PointerEventData eventData)
    {
        bx = true;
    }     public void OnPointerExit(PointerEventData eventData)
    {
        bx = false;
    }
    void Start()
    {
    } }

  

Unity打包PC端各种屏幕适配,无边框,最小化,显示可拖拽部分的更多相关文章

  1. Qt无边框窗体-最大化时支持拖拽还原

    目录 一.概述 二.效果展示 三.demo制作 1.设计窗体 2.双击放大 四.拖拽 五.相关文章 原文链接:Markdown模板 一.概述 用Qt进行开发界面时,既想要实现友好的用户交互又想界面漂亮 ...

  2. 再谈移动端Web屏幕适配

    一个多月前水了一篇移动web屏幕适配方案,当时噼里啪啦的写了一通,自我感觉甚是良好.不过最近又有一些新的想法,和之前的有一些不同. 先说一下淘宝的方案,感觉现在好多的适配方案都是受了它的影响,上周六看 ...

  3. Unity输出PC端(Windows) 拖拽文件到app中

    需求:给策划们写一个PC端(Window)的Excel导表工具.本来用OpenFile打开FileExplorerDialog后让他们自己选择想要添加的Excel文件就行了,结果有个需求是希望能拖拽E ...

  4. h5微信页面在手机微信端和微信web开发者工具中都能正常显示,但是在pc端微信浏览器上打不开(显示空白)

    h5微信页面在手机微信和微信开发者工具中都能正常显示,但是在pc端微信浏览器上打不开或者数据加载不出来. 原因:pc端微信浏览器不支持ES6语法,我的代码中使用了一些ES6的特性 解决:将ES6转换为 ...

  5. Unity正交模式摄像机与屏幕适配的方法

    public class CameraAuto : MonoBehaviour { float fDefaultRatio = 720.0f / 1280.0f;//预先设定屏幕大小1280*720 ...

  6. PC端判断屏幕宽度到达手机宽度的时候,直接跳转手机页面

    <script> // //判断屏幕宽度到达手机宽度的时候,直接跳转手机页面 // window.addEventListener("resize", function ...

  7. Unity 打包PC和安卓的路径注意事项

    if UNITY_STANDALONE_WIN || UNITY_EDITOR return Application.persistentDataPath + "/LocalData&quo ...

  8. Qt无边框窗体-模拟模态窗体抖动效果

    目录 一.概述 二.效果展示 三.功能实现 四.相关文章 原文链接:Qt无边框窗体-模拟模态窗体抖动效果 一.概述 用Qt开发windows客户端界面确实是一大利器,兼顾性能的同时,速度相对来说也不错 ...

  9. (响应式PC端媒体查询)电脑屏幕分辨率尺寸大全

    (响应式PC端媒体查询)电脑屏幕分辨率尺寸大全 时间:2015-08-17 16:50:40      阅读:3961      评论:0      收藏:0      [点我收藏+] 标签:styl ...

随机推荐

  1. 【JS】JS格式化文件大小 单位:Bytes、KB、MB、GB

    输入一个表示文件大小的数字,自适应转换到KB,MB,GB 方法一:bytes自适应转换到KB,MB,GB /// <summary> /// 格式化文件大小的JS方法 /// </s ...

  2. I/O模型之四:Java 浅析I/O模型(BIO、NIO、AIO、Reactor、Proactor)

    目录: <I/O模型之一:Unix的五种I/O模型> <I/O模型之二:Linux IO模式及 select.poll.epoll详解> <I/O模型之三:两种高性能 I ...

  3. jest-babel报错:Requires Babel "^7.0.0-0", but was loaded with "6.26.3"

    解决方法: yarn remove jest babel-jest babel-core @babel/core yarn add --dev jest babel-jest babel-core@^ ...

  4. 【1】【leetcode-93】复原IP地址

    (不会,典型) 给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式. 示例: 输入: "25525511135" 输出: ["255.255.11.135 ...

  5. Python复习笔记(十)Http协议--Web服务器-并发服务器

    1. HTTP协议(超文本传输协议) 浏览器===>服务器发送的请求格式如下:(浏览器告诉服务器,浏览器的信息) GET / HTTP/1.1 Host: www.baidu.com Conne ...

  6. Basic berkeley socket functions

    gethostbyname() DNS を通して.Domain の Information を GET する.例えば IP Address なんだ. げん型: #include <netdb.h ...

  7. python 小技巧

    计算时间差,时间加减运算代码 最近在学习数据预处理,碰到日期型数据不会处理,上网查了下: Q:如何方便的计算两个时间的差,如两个时间相差几天,几小时等A:使用datetime模块可以很方便的解决这个问 ...

  8. oracle 任务备份

    @echo offset hour=%time:~,2%if "%time:~,1%"==" " set hour=0%time:~1,1%set temp=% ...

  9. [C++]Linux之网络实时检测功能

    声明:如需引用或者摘抄本博文源码或者其文章的,请在显著处注明,来源于本博文/作者,以示尊重劳动成果,助力开源精神.也欢迎大家一起探讨,交流,以共同进步,乃至成为朋友- 0.0 由于学习操作系统实验课程 ...

  10. 函数语法:原生JS获取数组的索引值index

    var lis = document.getElementsByTagName("li"); for(var i=0;i<lis.length;i++) { lis[i].i ...