Unity 改变发布好exe的位置大小

复制代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine;

public class WindowMOD: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 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;

    void Start() {
        string paths = Application.dataPath;
        if(paths.IndexOf("Assets")==-1) {
            Screen.fullScreen = false;
            StartCoroutine(Setposition());
        }
    }

    public IEnumerator Setposition() {
        yield return new WaitForSeconds(5f);      //不知道为什么发布于行后,设置位置的不会生效,我延迟0.1秒就可以
        SetWindowLong(GetForegroundWindow(),GWL_STYLE,WS_POPUP);//将网上的WS_BORDER替换成WS_POPUP  
        bool result = SetWindowPos(GetForegroundWindow(),0,(int)screenPosition.x,(int)screenPosition.y,(int)screenPosition.width,(int)screenPosition.height,SWP_SHOWWINDOW);

    }
}
复制代码

 

posted on   zqiang0803  阅读(121)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2019-01-18 as3.0 当fla里面有TLF文本的时候,加载声音会出现错误
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示