unity程序最小化,隐藏桌面和任务栏

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 initialization
void Start () {
    //程序窗口最小化
   ShowWindow(GetForegroundWindow(),SW_ShowMin);
 //   hideTaskbar();

}



/// 隐藏任务栏和桌面图标
/// 
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 按钮
    }
}

/// 
/// 显示任务栏和桌面图标 
/// 
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);
    }
}

你可能感兴趣的:(unity,unity3d)