Hide and Show taskbar on windows 10

一个人想着一个人 提交于 2021-02-10 14:53:58

问题


I have a wpf application which is in maximized state always without showing taskbar. Here is the code for Hiding and showing taskbar.

    [DllImport("user32.dll")]
    private static extern int FindWindow(string className, string windowText);

    [DllImport("user32.dll")]
    private static extern int ShowWindow(int hwnd, int command);

    private const int SW_HIDE = 0;
    private const int SW_SHOW = 1;

    static int hwnd = FindWindow("Shell_TrayWnd", "");

    public static new void Hide()
    {
        ShowWindow(hwnd, SW_HIDE);    
    }
    public static new void Show()
    {
        ShowWindow(hwnd, SW_SHOW);
    }

This is working fine on windows 7. But when application runs on Windows 10.. taskbar didnt show up again by calling show().

Here is the part where I am calling show()

  #region Show Desktop
    private void Desktop_MouseUp(object sender, MouseButtonEventArgs e)
    {
        if (e.ChangedButton == MouseButton.Left )
        {
            this.WindowState = System.Windows.WindowState.Minimized;
            Shell32.Shell objShel = new Shell32.Shell();              
            objShel.MinimizeAll();
            Show();
        }

    }

#endregion

回答1:


This works on the main display and is taken from here and converted to c#.

public static class Taskbar
{
    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern IntPtr FindWindow(
        string lpClassName,
        string lpWindowName);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern int SetWindowPos(
        IntPtr hWnd,
        IntPtr hWndInsertAfter,
        int x,
        int y,
        int cx,
        int cy,
        uint uFlags
    );

    [Flags]
    private enum SetWindowPosFlags : uint
    {
        HideWindow = 128,
        ShowWindow = 64
    }

    public static void Show()
    {
        var window = FindWindow("Shell_traywnd", "");
        SetWindowPos(window, IntPtr.Zero, 0, 0, 0, 0, (uint) SetWindowPosFlags.ShowWindow);
    }

    public static void Hide()
    {
        var window = FindWindow("Shell_traywnd", "");
        SetWindowPos(window, IntPtr.Zero, 0, 0, 0, 0, (uint)SetWindowPosFlags.HideWindow);
    }
}


来源:https://stackoverflow.com/questions/52889210/hide-and-show-taskbar-on-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!