Multiple screens in unity and maximized minimization

Source: Internet
Author: User

A multi-screen

The first is multi-screen, my needs are only shown on the second screen, and the first screen operation does not affect the second Screen.

If you have a different screen, you can choose which screen to display in the Configuration box when you open the Exe.

If you select the second block, do not delete the data folder, go back to Unity uncheck Display Resolution Diag, next open jump directly to the second fast Screen.

Two to solve the background of the second screen

But if this is the case, you will encounter a small problem-click on the main screen and the second screen will run to the Background.

I want to let the second screen, not affected by the first screen to run to the Background.

After trying,

If you check it, you Can.

Three. get the current window handle

The current window is its process, the way to search the window before, there is no good way

Then it was solved with the process.

Reference: http://www.jb51.net/article/36226.htm

Code:

public class User32api{private static Hashtable Processwnd = null;    Public delegate bool Wndenumproc (IntPtr hwnd, UINT lParam);        Static User32api () {if (processwnd = = Null) {processwnd = new Hashtable (); }} [DllImport ("user32.dll", entrypoint = "EnumWindows", SetLastError = true)] public static extern bool Enumwind    OWS (wndenumproc lpenumfunc, UINT lParam); [DllImport ("user32.dll", entrypoint = "GetParent", SetLastError = true)] public static extern IntPtr GetParent (IntPtr H    Wnd); [DllImport ("user32.dll", entrypoint = "getwindowthreadprocessid")] public static extern uint GetWindowThreadProcessId (    INTPTR hWnd, ref UINT lpdwprocessid);    [DllImport ("user32.dll", entrypoint = "iswindow")] public static extern bool IsWindow (INTPTR hWnd);    [DllImport ("kernel32.dll", entrypoint = "setlasterror")] public static extern void SetLastError (uint dwerrcode); public static IntPtr Getcurrentwindowhandle () {IntPtr pTrwnd = intptr.zero; UINT UIPID = (uint) process.getcurrentprocess ().  Id;        Current Process ID Object Objwnd = processwnd[uipid];            If (objwnd! = Null) {ptrwnd = (IntPtr) objwnd;            If (ptrwnd! = IntPtr.Zero && iswindow (ptrwnd))//get handle {return Ptrwnd from cache;            } Else {ptrwnd = intptr.zero;        }} bool bresult = EnumWindows (new wndenumproc (enumwindowsproc), uipid);  The enumeration window returns false with no error number indicating success if (!bresult && marshal.getlastwin32error () = = 0) {objwnd            = processwnd[uipid];            If (objwnd! = Null) {ptrwnd = (IntPtr) objwnd;    }} return ptrwnd;        } private static bool Enumwindowsproc (IntPtr hwnd, uint LParam) {uint uipid = 0;            If (GetParent (hwnd) = = Intptr.zero) {getwindowthreadprocessid (hwnd, ref uipid); If (uipid = = LParam)//find the process corresponding to the main window handle {processwnd[uipid] = hwnd;    Cache the Handle. SetLastError (0);   Set Error-free return false;    Returns false to terminate the enumeration window}} return true;  }}

Four. Maximize and Minimize

[DllImport ("user32.dll")]    public static extern bool ShowWindow (system.intptr hwnd, int ncmdshow); public void Setwindowmin ()    {        showwindow (user32api.getcurrentwindowhandle (), 2);//minimized    } public    Void Setwindowmax ()    {        showwindow (user32api.getcurrentwindowhandle (), 3);//minimized    }

Five. defining the interface

Local Unity program As Server (c # does server-side comparison Rip)

 Private Socket m_server;        void Start () {IPAddress local = Ipaddress.parse ("127.0.0.1");        IPEndPoint iep=new IPEndPoint (local,5099);        M_server=new Socket (addressfamily.internetwork,sockettype.stream, protocoltype.tcp); M_server.        Bind (iep); M_server.        Listen (5);        Thread Serverthread=new Thread (serveraccept);          Serverthread.start ();            }void Update () {} private void serveraccept () {while (true) {Debug.Log ("start receiving client information"); Gets the socket that contains the client information socket, client = M_server.            Accept ();            Debug.Log ("receive client");            Create a Message Service thread object Serverthread newclient = new Serverthread (client); Delegate the ClientService method of the Clientthread class to thread newthread = new Thread (newclient.            clientservice); Start the message service thread Newthread.        Start (20);//received length size}} public void Onapplicationquit () {Debug.Log ("exit"); M_server.    Close (); }

Using system.collections;
Using System.Collections.Generic;
Using system.net;
Using System.Net.Sockets;
Using system.text;
Using unityengine;

public class Serverthread
{


Private Socket m_client;
Public Serverthread (Socket Client)
{
This.m_client = client;
}

public void ClientService (object Param)
{
int fixedsize = (int) param;
String data = null;
byte[] bytes = null;

Debug.Log ("new Client Connection established:" + ((ipendpoint) M_client. Remoteendpoint). Address);
While ((bytes = ReceiveMessage (m_client, fixedsize)). Length! = 0)
{
data = System.Text.Encoding.ASCII.GetString (bytes, 0, fixedsize);
Debug.Log ("information received:" + data);
Processing the message sent by the client, this is converted to uppercase
Data=data. Trim (' N ');
Executeorder (data);


}
Close socket
M_client. Close ();
Debug.Log ("customer closes connection:" + ((ipendpoint) M_client. Remoteendpoint). Address);
}


byte[] ReceiveMessage (Socket s, int Size)
{
Size = 20;
int offset = 0;
int recv;
int dataleft = size;
byte[] msg = new byte[size];
While (dataleft > 0)
{
recv = s.receive (msg, offset, dataleft, 0);
if (recv = = 0)
{
Break
}
Offset + = recv;
dataleft-= recv;
}
Return msg;
}

public void Executeorder (string Order)
{

Debug.Log (sb.) ToString (). Length);
Switch (order)
{
Case "start":
Debug.Log ("enter Start case");
Loom.queueonmainthread (
() =
{
charactermanager.instance.getcomponent<charactermanager> (). isspeaking = true;
});

Break
Case "stop":
Loom.queueonmainthread (
() =
{
charactermanager.instance.getcomponent<charactermanager> (). isspeaking = false;
});
Debug.Log ("stop case");
Break
Case "max":
Loom.queueonmainthread (
() =
{
DisplayScript.Instance.SetWindowMax ();
});
Break
Case "min":
Loom.queueonmainthread (
() =
{
DisplayScript.Instance.SetWindowMin ();
});
Break

}
}

}


Note: Data=data. Trim (' N ');

Because the 0 conversion in byte to char is ' \ s ', instead of ', ' the ASCII code is 32.

Multiple screens in unity and maximized minimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.