unity里设置窗口大小和位置的代码

using System.Runtime.InteropServices;

#region DllImports
[ DllImport("user32.dll") ]
public static extern int WindowFromPoint(int xPoint,int yPoint);

[ DllImport("user32.dll") ]
public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);

//参数分别是:x,y分别表示窗口左上角在屏幕的什么位置,width,height为0表示不改变窗口大小。

[ DllImport("user32.dll") ]
public static extern int GetForegroundWindow();

[ DllImport("user32.dll") ]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[ DllImport("user32.dll") ]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[ DllImport("user32.dll") ]
public static extern int GetWindowText(int hwnd,string lpString,int cch); 

[DllImport("user32.dll")] 
public static extern IntPtr GetActiveWindow(); 

[DllImport("user32.dll")] 
public static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")] 
public static extern long SetWindowLong(IntPtr hWnd,int nIndex,long dwNewLong);
#endregion

IEnumerator forceRes () {
yield return new WaitForSeconds(2);
Screen.SetResolution(3840, 1620, false);
yield return new WaitForSeconds(2);
SetWindowPos(GetActiveWindow(),-1,0,0,0,0,0x001);
}


你可能感兴趣的:(unity)