c# 设置自动隐藏任务栏、获取状态

from:

http://stackoverflow.com/questions/1381821/how-to-toggle-switch-windows-taskbar-from-show-to-auto-hide-and-vice-versa

[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 =
        0x00000000,
        Remove =
        0x00000001,
        QueryPos =
        0x00000002,
        SetPos =
        0x00000003,
        GetState =
        0x00000004,
        GetTaskBarPos =
        0x00000005,
        Activate =
        0x00000006,
        GetAutoHideBar =
        0x00000007,
        SetAutoHideBar =
        0x00000008,
        WindowPosChanged =
        0x00000009,
        SetState =
        0x0000000a
    }

    [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 =
        0x00000001,
        AlwaysOnTop =
        0x00000002
    }

/// <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);
    }

When the code above is implemented just set the Taskbar to autohide by:SetTaskbarState(AppBarStates.AutoHide);

Get the current state by:

AppBarStates currentState = GetTaskbarState();


转载于:https://www.cnblogs.com/runliuv/p/3501769.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值