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 extern static IntPtr FindWindow(string lpClassName, string lpWindowName);[DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);const int SW_ShowMin = 2;//最小化const int SW_ShowMax = 3;//最大化const int SW_ShowStore = 1;//还原// Use this for initializationvoid Start () {//程序窗口最小化ShowWindow(GetForegroundWindow(),SW_ShowMin);// hideTaskbar();}/// 隐藏任务栏和桌面图标/// </summary>public void hideTaskbar(){IntPtr trayHwnd = FindWindow("Shell_TrayWnd", null);IntPtr hStar = FindWindow("Button", null);IntPtr desktopPtr = FindWindow("Progman", null);if (trayHwnd != IntPtr.Zero){ShowWindow(desktopPtr, 0);//隐藏桌面图标 (0是隐藏,1是显示)ShowWindow(trayHwnd, 0);//隐藏任务栏ShowWindow(hStar, 0);//隐藏windows 按钮}}/// <summary>/// 显示任务栏和桌面图标 /// </summary>public void showTaskbar(){IntPtr trayHwnd = FindWindow("Shell_TrayWnd", null);IntPtr hStar = FindWindow("Button", null);IntPtr desktopPtr = FindWindow("Progman", null);if (trayHwnd != IntPtr.Zero){ShowWindow(desktopPtr, 1);ShowWindow(trayHwnd, 1);ShowWindow(hStar, 1);}}