Unity打包EXE自定义(拖拽)窗口大小
2023-12-13 20:29:07
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.InteropServices;
public class MyWindow : MonoBehaviour
{
[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; //最左坐标
public int Top; //最上坐标
public int Right; //最右坐标
public int Bottom; //最下坐标
}
[DllImport("user32.dll")]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
//***********************
IntPtr myintptr;
RECT rect;
float w_h;
int w;
int h;
int x;
int y;
void Start()
{
myintptr = GetActiveWindow();
w_h = 9f / 16f; //窗口横纵比例
GetWindowRect(myintptr, ref rect);
w = rect.Right - rect.Left; //窗口的宽度
h = rect.Bottom - rect.Top; //窗口的高度
}
void LateUpdate()
{
SetWindow();
}
void SetWindow()
{
GetWindowRect(myintptr, ref rect);
w = rect.Right - rect.Left; //窗口的宽度
h = rect.Bottom - rect.Top; //窗口的高度
x = rect.Left;
y = rect.Top;
float z = w / h;
if (z > w_h + 0.01f || z < w_h - 0.01f)
{
h = (int)(w / w_h);
MoveWindow(myintptr, x, y, w, h, true);
}
}
}
设置
文章来源:https://blog.csdn.net/Dore__/article/details/134824106
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!