如何切换/从“秀” Windows任务栏切换到“自动隐藏”(反之亦然)?(How to toggle

2019-07-04 22:27发布

基本上我想要做(如果在自动隐藏,相反,以正常显示模式)设置任务栏自动隐藏模式,如果在正常模式下简单的切换程序(将被映射到一些键盘快捷键)。

你知道如何实现它在C#中? (或Win32的C ++,但任何将真正做到这一点是好的。)

谢谢。 希望我已经说清楚了。

-

我真的不希望任何全屏应用程序,将任务栏重叠,只是没有窗户的程序,切换显示模式和退出。 我从自动隐藏切换到普通视图定期,并希望简化它。 (使用Win7的。)

-

编辑。 例如

#include <windows.h>

int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    SetWindowPos(FindWindow(L"Shell_traywnd", NULL ), 0, 0, 0, 0, 0, 0x40);
}

不会做的伎俩,那只能说明任务栏上,这已经是可见=真实的,但不是从自动隐藏切换到/。 (同样适用于0x80的。)

Answer 1:

任务栏是一个appbar,你可以控制它SHAppBarMessage



Answer 2:

下面是我使用的功能:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);

[DllImport("shell32.dll")]
public static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref APPBARDATA pData);

public enum AppBarMessages
{
    New              = 0x00,
    Remove           = 0x01,
    QueryPos         = 0x02,
    SetPos           = 0x03,
    GetState         = 0x04,
    GetTaskBarPos    = 0x05,
    Activate         = 0x06,
    GetAutoHideBar   = 0x07,
    SetAutoHideBar   = 0x08,
    WindowPosChanged = 0x09,
    SetState         = 0x0a
}

[StructLayout(LayoutKind.Sequential)]
public struct APPBARDATA
{
    public UInt32 cbSize;
    public IntPtr hWnd;
    public UInt32 uCallbackMessage;
    public UInt32 uEdge;
    public Rectangle rc;
    public Int32 lParam;
}

public enum AppBarStates
{
    AutoHide    = 0x01,
    AlwaysOnTop = 0x02
}

/// <summary>
/// Set the Taskbar State option
/// </summary>
/// <param name="option">AppBarState to activate</param>
public void SetTaskbarState(AppBarStates option)
{
    APPBARDATA msgData = new APPBARDATA();
    msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
    msgData.hWnd = FindWindow("System_TrayWnd", null);
    msgData.lParam = (Int32)(option);
    SHAppBarMessage((UInt32)AppBarMessages.SetState, ref msgData);
}

/// <summary>
/// Gets the current Taskbar state
/// </summary>
/// <returns>current Taskbar state</returns>
public AppBarStates GetTaskbarState()
{
    APPBARDATA msgData = new APPBARDATA();
    msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
    msgData.hWnd = FindWindow("System_TrayWnd", null);
    return (AppBarStates)SHAppBarMessage((UInt32)AppBarMessages.GetState, ref msgData);
}

当上面的代码被实现只需设置任务栏通过为自动隐藏: SetTaskbarState(AppBarStates.AutoHide);

通过获取当前状态:

AppBarStates currentState = GetTaskbarState();


Answer 3:

我跟着@Quispie答案,但它并不能在Windows 10在第一个工作,但给我的基础和源头上解决它(这样的荣誉),也http://www.pinvoke.net/ 。

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);

[DllImport("shell32.dll")]
public static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref APPBARDATA pData);

public enum AppBarMessages
{
    New = 0x00,
    Remove = 0x01,
    QueryPos = 0x02,
    SetPos = 0x03,
    GetState = 0x04,
    GetTaskBarPos = 0x05,
    Activate = 0x06,
    GetAutoHideBar = 0x07,
    SetAutoHideBar = 0x08,
    WindowPosChanged = 0x09,
    SetState = 0x0a
}

[StructLayout(LayoutKind.Sequential)]
public struct APPBARDATA
{
    public int cbSize; // initialize this field using: Marshal.SizeOf(typeof(APPBARDATA));
    public IntPtr hWnd;
    public uint uCallbackMessage;
    public uint uEdge;
    public RECT rc;
    public int lParam;
}

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
    public int Left, Top, Right, Bottom;

    public RECT(int left, int top, int right, int bottom)
    {
        Left = left;
        Top = top;
        Right = right;
        Bottom = bottom;
    }

    public RECT(System.Drawing.Rectangle r) : this(r.Left, r.Top, r.Right, r.Bottom) { }

    public int X
    {
        get { return Left; }
        set { Right -= (Left - value); Left = value; }
    }

    public int Y
    {
        get { return Top; }
        set { Bottom -= (Top - value); Top = value; }
    }

    public int Height
    {
        get { return Bottom - Top; }
        set { Bottom = value + Top; }
    }

    public int Width
    {
        get { return Right - Left; }
        set { Right = value + Left; }
    }

    public System.Drawing.Point Location
    {
        get { return new System.Drawing.Point(Left, Top); }
        set { X = value.X; Y = value.Y; }
    }

    public System.Drawing.Size Size
    {
        get { return new System.Drawing.Size(Width, Height); }
        set { Width = value.Width; Height = value.Height; }
    }

    public static implicit operator System.Drawing.Rectangle(RECT r)
    {
        return new System.Drawing.Rectangle(r.Left, r.Top, r.Width, r.Height);
    }

    public static implicit operator RECT(System.Drawing.Rectangle r)
    {
        return new RECT(r);
    }

    public static bool operator ==(RECT r1, RECT r2)
    {
        return r1.Equals(r2);
    }

    public static bool operator !=(RECT r1, RECT r2)
    {
        return !r1.Equals(r2);
    }

    public bool Equals(RECT r)
    {
        return r.Left == Left && r.Top == Top && r.Right == Right && r.Bottom == Bottom;
    }

    public override bool Equals(object obj)
    {
        if (obj is RECT)
            return Equals((RECT)obj);
        else if (obj is System.Drawing.Rectangle)
            return Equals(new RECT((System.Drawing.Rectangle)obj));
        return false;
    }

    public override int GetHashCode()
    {
        return ((System.Drawing.Rectangle)this).GetHashCode();
    }

    public override string ToString()
    {
        return string.Format(System.Globalization.CultureInfo.CurrentCulture, "{{Left={0},Top={1},Right={2},Bottom={3}}}", Left, Top, Right, Bottom);
    }
}


public enum AppBarStates
{
    AlwaysOnTop = 0x00,
    AutoHide = 0x01
}

/// <summary>
/// Set the Taskbar State option
/// </summary>
/// <param name="option">AppBarState to activate</param>
public void SetTaskbarState(AppBarStates option)
{
    APPBARDATA msgData = new APPBARDATA();
    msgData.cbSize = Marshal.SizeOf(msgData);
    msgData.hWnd = FindWindow("System_TrayWnd", null);
    msgData.lParam = (int)option;
    SHAppBarMessage((UInt32)AppBarMessages.SetState, ref msgData);
}

/// <summary>
/// Gets the current Taskbar state
/// </summary>
/// <returns>current Taskbar state</returns>
public AppBarStates GetTaskbarState()
{
    APPBARDATA msgData = new APPBARDATA();
    msgData.cbSize = Marshal.SizeOf(msgData);
    msgData.hWnd = FindWindow("System_TrayWnd", null);
    return (AppBarStates)SHAppBarMessage((UInt32)AppBarMessages.GetState, ref msgData);
}


Answer 4:

隐藏任务栏

它比C#更WIN32 API相关的问题。 你可以使用这个 (需要翻译成点当然后的净额)隐藏任务栏。

您可以使用http://www.pinvoke.net翻译的WIN32 API调用来点网。

设置自动隐藏到任务栏

您可以通过操纵使用所描述的键在注册表实现这一这里 。

它应该是一件容易的事,祝你好运。



Answer 5:

我maked任务栏类从这个像这样的代码:

public class Taskbar
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);
[DllImport("shell32.dll")]
public static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref APPBARDATA pData);
public enum AppBarMessages
{
    New = 0x00,
    Remove = 0x01,
    QueryPos = 0x02,
    SetPos = 0x03,
    GetState = 0x04,
    GetTaskBarPos = 0x05,
    Activate = 0x06,
    GetAutoHideBar = 0x07,
    SetAutoHideBar = 0x08,
    WindowPosChanged = 0x09,
    SetState = 0x0a
}
[StructLayout(LayoutKind.Sequential)]
public struct APPBARDATA
{
    public UInt32 cbSize;
    public IntPtr hWnd;
    public UInt32 uCallbackMessage;
    public UInt32 uEdge;
    public Rectangle rc;
    public Int32 lParam;
}
public enum AppBarStates
{
    AutoHide = 0x01,
    AlwaysOnTop = 0x02
}
/// <summary>
/// Set the Taskbar State option
/// </summary>
/// <param name="option">AppBarState to activate</param>
public void SetTaskbarState(AppBarStates option)
{
    APPBARDATA msgData = new APPBARDATA();
    msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
    msgData.hWnd = FindWindow("System_TrayWnd", null);
    msgData.lParam = (Int32)(option);
    SHAppBarMessage((UInt32)AppBarMessages.SetState, ref msgData);
}
/// <summary>
/// Gets the current Taskbar state
/// </summary>
/// <returns>current Taskbar state</returns>
public AppBarStates GetTaskbarState()
{
    APPBARDATA msgData = new APPBARDATA();
    msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
    msgData.hWnd = FindWindow("System_TrayWnd", null);
    return (AppBarStates)SHAppBarMessage((UInt32)AppBarMessages.GetState, ref msgData);
}
}

问题是,当我表演

taskbar.SetTaskbarState(Taskbar.AppBarStates.AlwaysOnTop);

taskbar.SetTaskbarState(Taskbar.AppBarStates.AutoHide);

我的启动按钮不再是激活的(我无法打开STARTMENU,点击它这么想的原因一切)。 我使用的是Windows 10,没有人知道关于这个解决方案?



Answer 6:

这是我使用的解决方案:7+任务栏调教( http://rammichael.com/7-taskbar-tweaker )。 荣誉对作者!

一个简单的免费程序,使得它可以切换任务栏自动隐藏在一个动作 - 在分配给双倍任务栏的空白处单击或中间点击或自己设置(见高级选项+的帮助,点击右键试试图标) 。

因为我用任务栏在垂直位置,在笔记本电脑上我跑出空当我投射到XVGA,这是常见的这对我来说至关重要。 这是一个真正的痛苦,那么多的点击切换它。

这是微软并没有因为90年代进一步发展了这一遗憾。 今天,我想一个办法是,它表现为在Office程序中的功能区。

干杯!

马里安



Answer 7:

对于那些谁从谷歌来到这里使用的是Windows 10,和我一样,从@Quispie的答案,@nicruo是确定的,但需要一个额外的if

其原因是类的名字从版本不同到版本(显然,因为我不再有任何其他的Windows,但10)。

msgData.hWnd = FindWindow("System_TrayWnd", null);
if (msgData.hWnd == IntPtr.Zero)
    msgData.hWnd = FindWindow("Shell_TrayWnd", null);


文章来源: How to toggle/switch Windows taskbar from “show” to “auto-hide” (and vice-versa)?