声明太多就不都贴了,这些都是网上找的代码
代码如下
public enum appStyle {
FullScreen = 0,
WindowedFullScreen = 1,
Windowed = 2,
WindowedWithoutBorder = 3,
}
public appStyle AppWindowStyle = appStyle.WindowedFullScreen;
public enum zDepth {
Normal = 0,
Top = 1,
TopMost = 2,
}
public zDepth ScreenDepth = zDepth.Normal;
public int windowLeft = 10;
public int windowTop = 10;
public int windowWidth = 800;
public int windowHeight = 600;
const uint SWP_NOMOVE = 0x0002;
const uint SWP_FRAMECHANGED = 0x0020;
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
private Rect screenPosition;
private const int GWL_EXSTYLE = (-20);
private const int WS_CAPTION = 0xC00000;
private const int WS_POPUP = 0x800000;
IntPtr HWND_TOP = new IntPtr(0);
IntPtr HWND_TOPMOST = new IntPtr(-1);
IntPtr HWND_NORMAL = new IntPtr(-2);
private const int SM_CXSCREEN = 0x00000000;
private const int SM_CYSCREEN = 0x00000001;
int Xscreen;
int Yscreen;
void Start ()
{
Xscreen = (int)GetSystemMetrics(SM_CXSCREEN);
Yscreen = (int)GetSystemMetrics(SM_CYSCREEN);
//这种情况
if((int)AppWindowStyle == 1)
{
Screen.SetResolution(Xscreen-1,Yscreen-60,false);
screenPosition = new Rect(0,0,Xscreen-1,Yscreen-1);
}
}
int i = 0;
void Update () {
//然后我不明白为什么要在Update设置,直接在Start设置不好吗?
//我调了很多参数发现都改不了窗口的位置,而且我的目的是在单屏情况和双屏情况都窗口全屏显示在第一个屏幕上
if (i < 5)
{
if ((int)AppWindowStyle == 1)
{
if ((int)ScreenDepth == 2)
SetWindowPos(GetForegroundWindow(), HWND_TOPMOST, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);
ShowWindow(GetForegroundWindow(), 3);
}
}
i++;
}