Unity无边框PC 包

这篇博客介绍了如何使用C#的DllImport特性调用Windows API,将Unity游戏窗口设置为无边框模式。通过指定窗口风格、位置和大小,实现了自定义窗口的显示效果。主要涉及的技术包括Unity、C#编程和Windows API交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Unity无边框PC 包


	[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 SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong);
    [DllImport("user32.dll")]
     static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
    [DllImport("user32.dll")]
     static extern IntPtr GetForegroundWindow();
    [DllImport("User32.dll")]
     static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
	//无边窗口 
    private int winWidth;// 窗口宽度   
    private int winHeight;// 窗口高度   
    private int winPosX;// 窗口左上角x   
    private int winPosY;// 窗口左上角y
    const int GWL_STYLE = -16;
    const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}
    const int WS_POPUP = 0x800000;
    const uint SWP_SHOWWINDOW = 0x0040;


	IEnumerator WindowWithoutFrame()
    {//默认分辨率无边框显示(可以自由根据winWidth和winHeight的值调整无边框的分辨率)
        winWidth = 960;
        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;
        IntPtr hwnd = FindWindow(null, "WindowName");
        yield return new WaitForSeconds(0.1f);
         SetWindowLong(hwnd, GWL_STYLE, WS_POPUP);
        bool result =  SetWindowPos(hwnd, 0, winPosX, winPosY, winWidth, winHeight, SWP_SHOWWINDOW);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值