Home > Back-end >  Unity pseudo full screen, in the case of double screen how to change the window position
Unity pseudo full screen, in the case of double screen how to change the window position

Time:12-08

This is the code on the net, the along while don't know how to modify the position of the window, I said is WindowedFullScreen this kind of situation, and most of the resolution will be among the location of the transferred to the double screen window mode, how to solve this, I just want to in the current screen, just the current screen, full screen, sandwiched between two screens is too strange, also take their own, in addition, if can explain the code

Using System;

Using System. The Collections;

Using System. The Runtime. InteropServices;

Using System. Diagnostics;

Using UnityEngine;

Public class WindowMod: MonoBehaviour

{

[DllImport (" user32. DLL)]
The static extern IntPtr GetForegroundWindow ();

[DllImport (" user32. DLL, "CharSet=CharSet. Auto)]
Public static extern bool SetWindowPos (IntPtr hWnd, IntPtr hPos, int x, int y, cx, int int cy, uint nflags);

[DllImport (" User32. DLL, "EntryPoint=" FindWindow ")]
Private static extern IntPtr FindWindow (string lpClassName, string lpWindowName);

[DllImport (" User32. DLL, "EntryPoint=" SetWindowLong ")]
Private static extern int SetWindowLong (IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport (" User32. DLL, "EntryPoint=" GetWindowLong ")]
Private static extern int GetWindowLong (IntPtr hWnd, int dwNewLong);

[DllImport (" User32. DLL, "EntryPoint=" MoveWindow ")]
Private static extern bool MoveWindow (IntPtr hWnd, int x, int y, int width, int height, bool repaint);

[DllImport (" user32. DLL, "EntryPoint=" ShowWindow, "CharSet=CharSet. Auto)]
Public static extern int ShowWindow (IntPtr HWND, int nCmdShow);

[DllImport (" user32. DLL, "EntryPoint=" SendMessage ", CharSet=CharSet. Auto)]
Public static extern int SendMessage (IntPtr HWND, int MSG, IntPtr wP, IntPtr IP);

[DllImport (" user32. DLL, "EntryPoint=" SetParent CharSet=CharSet. Auto)]
Public static extern IntPtr SetParent (IntPtr hChild, IntPtr hParent);

[DllImport (" user32. DLL, "EntryPoint=" GetParent, "CharSet=CharSet. Auto)]
Public static extern IntPtr GetParent (IntPtr hChild);

[DllImport (" User32. DLL, "EntryPoint=" GetSystemMetrics ")]
Public static extern IntPtr GetSystemMetrics (int nIndex);

[DllImport (" user32. DLL)]
The static extern IntPtr GetActiveWindow ();

Public enum appStyle {
FullScreen=0,
WindowedFullScreen=1,
Windowed=2,
WindowedWithoutBorder=3,
}
Public appStyle AppWindowStyle=appStyle. Windowed;

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_SHOWWINDOW=0 x0040;
Const int GWL_STYLE=- 16;
Const int WS_BORDER=1;
Private the Rect screenPosition;
Private const int GWL_EXSTYLE=(20);
Private const int WS_CAPTION=0 xc00000;
Private const int WS_POPUP=0 x800000;
IntPtr HWND_TOP=new IntPtr (0);
IntPtr HWND_TOPMOST=new IntPtr (1);
IntPtr HWND_NORMAL=new IntPtr (2);

Private const int SM_CXSCREEN=0 x00000000;
Private const int SM_CYSCREEN=0 x00000001;

Int Xscreen;
Int Yscreen;

Void the Start ()
{

Xscreen=(int) GetSystemMetrics (SM_CXSCREEN);
Yscreen=(int) GetSystemMetrics (SM_CYSCREEN);
}

Void ChanegeWindowMode ()
{

If ((int) AppWindowStyle==0)
{
Screen. SetResolution (Xscreen Yscreen, true);
}
If ((int) AppWindowStyle==1)
{
Screen. SetResolution (Xscreen - 1, Yscreen - 40, false);
Xscreen screenPosition=new the Rect (0, 0, 1, Yscreen - 1);
}
If ((int) AppWindowStyle==2)
{
Screen. SetResolution (windowWidth, windowWidth, false);
}
If ((int) AppWindowStyle==3)
{
Screen. SetResolution (windowWidth, windowWidth, false);
ScreenPosition=new the Rect (windowLeft windowTop, windowWidth, windowWidth);
}

}

Void ChangeResolution (int sizeX, int sizeY)
{
WindowWidth=sizeX;
WindowHeight=sizeY;
}

int i=0;
Void the Update () {

If (Input. GetKeyUp (KeyCode. Q))
{
AppWindowStyle=appStyle. FullScreen;
Print (" FullScreen ");
}
If (Input. GetKeyUp (KeyCode. W))
{
AppWindowStyle=appStyle. WindowedFullScreen;
Print (" WindowedFullScreen ");
}
If (Input. GetKeyUp (KeyCode. E))
{
AppWindowStyle=appStyle. Windowed;
Print (" Windowed ");
}
ChanegeWindowMode ();

If (I & lt; 5)
{
If ((int) AppWindowStyle==1)
{
SetWindowLong (GetForegroundWindow () - 16, 369164288);
If ((int) ScreenDepth==0)
HWND_NORMAL SetWindowPos (GetForegroundWindow (), (int) screenPosition. X, (int) screenPosition. Y, (int) screenPosition. Width, (int) screenPosition. Height, SWP_SHOWWINDOW);
If ((int) ScreenDepth==1)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related