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();
[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);
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);
IntPtr Handle;
float xx;
bool bx;
void Start()
bx = false;
xx = 0f;
#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
void Update()
#if UNITY_STANDALONE_WIN
//拖拽(为了不让程序固定住,设置可拖拽,长按到达指定时间)
if (Input.GetMouseButtonDown(0))
xx = 0f;
bx = true;
if (bx && xx >= 0.3f)
{ //这样做为了区分界面上面其它需要滑动的操作
ReleaseCapture();
SendMessage(Handle, 0xA1, 0x02, 0);
SendMessage(Handle, 0x0202, 0, 0);
if (bx)
xx += Time.deltaTime;
if (Input.GetMouseButtonUp(0))
xx = 0f;
bx = false;
#endif
自己前一段时间一直查找相关资料、一直都没有,百度出来的都是一模一样的
最大
化、
最小化
、无
边框
的功能,就是没有
拖拽
的功能,自己搞定了就贴代码出来,省的其它程序员走弯路。
直接上代码,看注释。看不懂的就留言吧。using
Unity
Engine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
启动程序时添加-popupwindow参数即可将
Unity
窗口
设置成无
边框
样式。
例如,
打包
出来的可执行文件是demo.exe,那么在命令行中使用命令demo.exe -popupwindow就可以以无
边框
窗口
形式启动该程序。
为了方便使用,可以写一个批处理文件(bat):
:: 以无
边框
窗口
形式启动程序
start <exe_path> -popupwin...
//通过非托管方式导入dll。这里是导入user32.dll。
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dl.
Windows系统
unity
程序
最小化
,隐藏桌面和任务栏
[DllImport(“user32.dll”)]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public exter
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using
Unity
Engine;
public class WindowMaxAndMin : MonoBehaviour {
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntP
将下面代码复制进入脚本里,然后随便放到一个物体上即可实现
窗口
化启动无
边框
哦~using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics;
using
Unity
Engine;
public class WindowMod : MonoBehavi